2 #include <sys/socket.h>
4 #include <netinet/in.h>
33 struct commands my_commands
;
34 struct sensors my_sensors
;
36 /***************CLIENT****************/
38 void *Receive(void *my_socket
)
40 int rc
, socket
=(int) my_socket
;
41 char rec
[sizeof(my_sensors
)];
43 printf("\n<Receive> started");
47 rc
=recv(socket
, (struct sensors
*)&my_sensors
, sizeof(my_sensors
),0);
48 printf("\n%d Bytes empfangen", rc
);
49 printf("sensors x: %d", (int)my_sensors
.x
);
54 void *Parser(void *my_socket
)
56 int socket
=(int) my_socket
;
61 printf("\n<Parser> started");
67 if(strstr(input
, "startx"))
70 printf("\nxon %d", my_commands
.xon
);
72 if(strstr(input
, "forward"))
82 printf("\nxon %d", my_commands
.xon
);
91 printf("\nxon %d", my_commands
.xon
);
92 printf(" xdir %d", my_commands
.xdir
);
93 printf(" yon %d", my_commands
.yon
);
94 printf(" ydir %d", my_commands
.ydir
);
95 printf(" zon %d", my_commands
.zon
);
96 printf(" zdir %d", my_commands
.zdir
);
97 printf(" grep %d", my_commands
.grep
);
99 len
=send(socket
, (struct commands
*)&my_commands
, sizeof(my_commands
),0);
100 printf("\nsent %d bytes",len
);
106 int main(int argc
, char *arcv
[])
110 struct sockaddr_in addresinfo
;
111 unsigned short int portnmbr
= 5000;
112 char ip_addres
[] = "127.0.0.1";
114 pthread_t parser
, receive
;
118 my_commands.xdir = 0;
120 my_commands.ydir = 0;
122 my_commands.zdir = 0;
123 my_commands.grep = 0;
125 printf("\n Client gestartet");
127 socket_nmbr
= socket(AF_INET
, SOCK_STREAM
, 0);
128 addresinfo
.sin_family
= AF_INET
;
129 addresinfo
.sin_addr
.s_addr
= inet_addr(ip_addres
);
130 addresinfo
.sin_port
= htons(portnmbr
);
131 length
= sizeof(addresinfo
);
133 if (!connect(socket_nmbr
, (struct sockaddr
*)&addresinfo
, length
))
135 printf("\n Client: Verbindungsaufbau erfolgreich an");
136 printf(" IP %s - Port %d", ip_addres
, portnmbr
);
139 rc
= pthread_create(&parser
, NULL
, Parser
, (void *) socket_nmbr
);
141 printf("ERROR; return code from pthread_create() send is %d\n", rc
);
145 rc
= pthread_create(&receive
, NULL
, Receive
, (void *) socket_nmbr
);
147 printf("ERROR; return code from pthread_create() send is %d\n", rc
);
154 printf("\n Client beendet");