| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "include/tcp.h"
- #include "include/udp.h"
- //#include "rtc.h"
- #include <unistd.h>
- #include <pthread.h>
- #include <string.h>
- #if 1
- #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 *udp_recv(void *arg)
- {
- struct sockaddr_in recv_cin;
- struct msg recv_str[BUFSIZ];
- udp_broad_recv_init(BROADCAST_RECV_IP, BROADCAST_PORT_UDP);
- while (1)
- {
- udp_broad_recv_from(&recv_cin, recv_str);
- printf("2.%s\n", (char *)recv_str);
- }
- pthread_exit(NULL);
- }
- void *tcp_send(void *arg)
- {
- static char *send_str = "hello world";
- // open_rtc();
- while (1)
- {
- sleep(1);
- // send_str =read_rtc();
- // tcp_send_to(OTHER_IP, OTHER_PORT_TCP, (char *)send_str, strlen(send_str)+1);
- }
- pthread_exit(NULL);
- }
- int main(int argc, char *argv[])
- {
- pthread_t tid1;
- pthread_t tid2;
-
- pthread_create(&tid1, NULL, udp_recv, NULL);
- pthread_create(&tid2, NULL, tcp_send, NULL);
-
- pthread_join(tid1, NULL);
- pthread_join(tid2, NULL);
- return 0;
- }
|