-
Notifications
You must be signed in to change notification settings - Fork 10
/
rudpsel.c
65 lines (53 loc) · 1.07 KB
/
rudpsel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "rudp.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
//===================================================================
int main(int argc, char *argv[])
{
struct sockaddr_in sai;
RUDPSOCKET s;
RUDPStart();
s = RUDPSocket();
memset(&sai, 0, sizeof(sai));
sai.sin_family = AF_INET;
sai.sin_addr.s_addr = argc==2?inet_addr(argv[1]):htonl(INADDR_ANY);
sai.sin_port = htons(5001);
if(RUDPBind(s, (struct sockaddr*)&sai, sizeof(sai)) < 0)
{
perror("bind");
return -1;
}
RUDPListen(s, 5);
int ic = 0;
char cBusy[] = "-\\|/";
while(1)
{
struct timeval tv = { 0, 500000 };
if(RUDPSelectSock(s, -1, RUDPSELECT_READABLE, &tv) > 0)
{
int sa_len = sizeof(sai);
RUDPSOCKET a;
if(RUDPAccept(s, &a, (struct sockaddr*)&sai, &sa_len) < 0)
{
printf("accept error\n");
}
else
RUDPClose(a);
}
else
{
#if 0
printf("\r%c", cBusy[ic]); fflush(stdout);
ic = (ic+1)%4;
#else
printf("\r%d", ic++); fflush(stdout);
#endif
}
}
RUDPClose(s);
RUDPCleanup();
return 0;
}