3 * Demo for RUDPSimConnnect(...)
10 #include "platform_adpt.h"
14 void *recv_thread(void *p)
16 struct timeval tv = { 1, 0 };
24 RUDP_SET(s, 0, rset, nr);
25 if((rlt = RUDPSelect(rset, &nr, NULL, NULL, NULL, NULL, &tv)) > 0)
29 if(RUDP_ISSET(s, rset, nr))
31 len = RUDPRecv(s, &chno, line, 1000, 0);
37 printf("%s: %s\n", rudp?"rudp":"udp", line);
41 printf("Recv Error %d\n", len);
52 printf("RUDPSelect: %d\n", rlt);
60 int main(int argc, char *argv[])
62 struct sockaddr_in sai;
65 if(argc < 2) { printf("simconn remotehost [localport remoteport]\n"); return -1; }
72 memset(&sai, 0, sizeof(sai));
73 sai.sin_family = AF_INET;
74 sai.sin_port = htons(argc>2?atoi(argv[2]):5001);
75 if(RUDPBind(s, (struct sockaddr*)&sai, sizeof(sai)) < 0)
77 printf("bind to local port %d failed\n", ntohs(sai.sin_port));
82 //RUDPSetSockOpt(s, OPT_ADHOC, &i, sizeof(i));
85 if(argc > 3) sai.sin_port = htons(atoi(argv[3]));
86 sai.sin_addr.s_addr = inet_addr(argv[1]);
88 printf("begin connection....\n");
89 if(RUDPSimConnect(s, (struct sockaddr*)&sai, 1, NULL, 0) == 0)
97 pthread_create(&thd, NULL, recv_thread, NULL);
100 while(fgets(line, 1000, stdin))
102 int rlt, flag = RUDPSELECT_WRITABLE;
103 struct timeval tv = { 0, 0 };
104 rlt = RUDPSelectSock(s, 0, flag, &tv);
107 if( (rlt = RUDPSend(s, 0, line, strlen(line), 0)) < 0)
109 printf("RUDPSend: %d\n", rlt);
119 printf("connect to %s failed\n", argv[1]);
123 printf("press Enter to terminate.");
124 fgets(line, 1000, stdin);