-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoordinate_server.cpp
53 lines (45 loc) · 1.17 KB
/
coordinate_server.cpp
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
/*
* coordinate_server.cpp
* FireBreath
*
* Created by Johan Bjork on 2/12/11.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include "coordinate_server.h"
#include "Gazify.h"
#define BUFLEN 512
#define PORT 20320
void *coordiate_thread(void *arg)
{
Gazify *g = (Gazify *)arg;
struct sockaddr_in si_me, si_other;
int s, i, slen=sizeof(si_other);
char buf[BUFLEN];
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
return NULL;
memset((char *) &si_me, 0, sizeof(si_me));
si_me.sin_family = AF_INET;
si_me.sin_port = htons(PORT);
si_me.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(s, (sockaddr *)&si_me, sizeof(si_me))==-1)
return NULL;
while(1) {
int x,y;
if (recvfrom(s, buf, BUFLEN, 0, (sockaddr*)&si_other, (socklen_t *)&slen)==-1) {
printf("aborting recv thread");
return NULL;
}
sscanf(buf,"%d %d\n",&x,&y);
g->gaze(x,y);
}
close(s);
return 0;
}