8 #define SERVER_SEND 0x01
9 #define SERVER_RECV 0x02
11 //===================================================================
12 int sendData(RUDPSOCKET sock)
17 memset(line, '1' + i%36, 3000);
20 for(i=0; 0<50000; i++)
22 struct timeval tv = { 0, 25000 };
23 int flag = RUDPSELECT_WRITABLE;
25 v[0].iov_base = v[1].iov_base = v[2].iov_base = line;
30 n_byt = v[0].iov_len + v[1].iov_len + v[2].iov_len;
31 if(RUDPSelectSock(sock, 1, flag, &tv) > 0)
33 rlt = RUDPSendV(sock, 1, v, 3, 0);
36 printf("RUDPSend error: %d\n", rlt);
45 printf("***************************************\n");
49 RUDPSend(sock, 0, line, 1, 0);
50 printf("all data sent.\n");
55 void recvData(RUDPSOCKET sock)
61 char cBusy[] = "-\\|/";
65 struct timeval tv = { 0, 500000 };
66 int flag = RUDPSELECT_READABLE, rlt;
67 if((rlt = RUDPSelectSock(sock, -1, flag, &tv)) > 0)
69 if((len = RUDPRecv(sock, &chno, line, 2000, 0)) > 0)
75 fprintf(stderr, "RUDPRecv: %d\n", len);
80 printf("ERROR: RUDPSelectSock: %d\n", rlt);
84 printf("\r%c", cBusy[ic]); fflush(stdout);
88 printf("receiving finished.\n");
91 void *threadSend(void *p)
93 RUDPSOCKET sock = (RUDPSOCKET)p;
94 pthread_detach(pthread_self());
104 void* threadRecv(void *p)
106 RUDPSOCKET sock = (RUDPSOCKET)p;
107 pthread_detach(pthread_self());
116 int main(int argc, char *argv[])
118 struct sockaddr_in sai;
125 memset(&sai, 0, sizeof(sai));
126 sai.sin_family = AF_INET;
127 sai.sin_addr.s_addr = argc==2?inet_addr(argv[1]):htonl(INADDR_ANY);
128 sai.sin_port = htons(5001);
129 if(RUDPBind(s, (struct sockaddr*)&sai, sizeof(sai)) < 0)
137 int sa_len = sizeof(sai);
143 if(RUDPAccept(s, &a, (struct sockaddr*)&sai, &sa_len) < 0)
145 printf("accept error\n");
153 while((len = RUDPRecv(a, &chno, &cmd, 1, 0)) > 0)
158 if(cmd & SERVER_SEND)
159 pthread_create(&thd, NULL, threadSend, a);
160 if(cmd & SERVER_RECV)
161 pthread_create(&thd, NULL, threadRecv, a);
163 pthread_create(&thd, NULL, threadRecv, a);