| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "include/tcp.h"
- #include "include/udp.h"
- #include <unistd.h>
- #include <pthread.h>
- #include <string.h>
- #if 0
- #define SELF_PORT_UDP 5002
- #define SELF_PORT_TCP 5003
- #define SELF_IP "192.168.188.136" //自己IP
- #define OTHER_PORT_UDP 5004
- #define OTHER_PORT_TCP 5005
- #define OTHER_IP "192.168.188.136" //他人IP
- #define BROADCAST_PORT_UDP 5200
- #define BROADCAST_RECV_IP INADDR_ANY //广播IP
- #else
- #define OTHER_PORT_UDP 5002
- #define OTHER_PORT_TCP 5003
- #define OTHER_IP "192.168.188.136" //自己IP
- #define SELF_PORT_UDP 5004
- #define SELF_PORT_TCP 5005
- #define SELF_IP "192.168.188.136" //他人IP
- #define BROADCAST_PORT_UDP 5200
- #define BROADCAST_SEND_IP INADDR_BROADCAST //广播IP
- #endif
- void *tcp_recv(void *arg)
- {
- struct sockaddr_in recv_cin;
- char recv_str[BUFSIZ];
- static char *send_str = "hello,i have recv!";
- // tcp_recv_init(SELF_IP, SELF_PORT_TCP);
- while (1)
- {
- // tcp_recv_from(&recv_cin, recv_str);
- // printf("3.%s\n", recv_str);
- udp_broad_send_to(BROADCAST_SEND_IP, BROADCAST_PORT_UDP, (struct msg *)send_str, strlen(send_str)+1);
- sleep(1);
- }
- pthread_exit(NULL);
- }
- int main(int argc, char *argv[])
- {
- pthread_t tid1;
-
- pthread_create(&tid1, NULL, tcp_recv, NULL);
-
- pthread_join(tid1, NULL);
- return 0;
- }
|