clien.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "include/tcp.h"
  2. #include "include/udp.h"
  3. #include <unistd.h>
  4. #include <pthread.h>
  5. #include <string.h>
  6. #if 0
  7. #define SELF_PORT_UDP 5002
  8. #define SELF_PORT_TCP 5003
  9. #define SELF_IP "192.168.188.136" //自己IP
  10. #define OTHER_PORT_UDP 5004
  11. #define OTHER_PORT_TCP 5005
  12. #define OTHER_IP "192.168.188.136" //他人IP
  13. #define BROADCAST_PORT_UDP 5200
  14. #define BROADCAST_RECV_IP INADDR_ANY //广播IP
  15. #else
  16. #define OTHER_PORT_UDP 5002
  17. #define OTHER_PORT_TCP 5003
  18. #define OTHER_IP "192.168.188.136" //自己IP
  19. #define SELF_PORT_UDP 5004
  20. #define SELF_PORT_TCP 5005
  21. #define SELF_IP "192.168.188.136" //他人IP
  22. #define BROADCAST_PORT_UDP 5200
  23. #define BROADCAST_SEND_IP INADDR_BROADCAST //广播IP
  24. #endif
  25. void *tcp_recv(void *arg)
  26. {
  27. struct sockaddr_in recv_cin;
  28. char recv_str[BUFSIZ];
  29. static char *send_str = "hello,i have recv!";
  30. // tcp_recv_init(SELF_IP, SELF_PORT_TCP);
  31. while (1)
  32. {
  33. // tcp_recv_from(&recv_cin, recv_str);
  34. // printf("3.%s\n", recv_str);
  35. udp_broad_send_to(BROADCAST_SEND_IP, BROADCAST_PORT_UDP, (struct msg *)send_str, strlen(send_str)+1);
  36. sleep(1);
  37. }
  38. pthread_exit(NULL);
  39. }
  40. int main(int argc, char *argv[])
  41. {
  42. pthread_t tid1;
  43. pthread_create(&tid1, NULL, tcp_recv, NULL);
  44. pthread_join(tid1, NULL);
  45. return 0;
  46. }