Skip to content

Instantly share code, notes, and snippets.

@xymostech
Created April 21, 2013 22:56
Show Gist options
  • Save xymostech/41a005936bf52ac10cca to your computer and use it in GitHub Desktop.
Save xymostech/41a005936bf52ac10cca to your computer and use it in GitHub Desktop.
while(consocket){
/* read the joystick state */
read(joy_fd, &js, sizeof(struct js_event));
/* see what to do with the event */
switch (js.type & ~JS_EVENT_INIT)
{
case JS_EVENT_AXIS:
axis [ js.number ] = js.value;
break;
case JS_EVENT_BUTTON:
button [ js.number ] = js.value;
break;
}
//Give msg1 variable the value of axis[0]
sprintf(msg1, "%d", axis[0]);
//TCP send
char msg[] = "Hello";
printf("Value is: %d\n", axis[0]);
//printf("Incoming connection from %s - sending welcome\n", inet_ntoa(dest.sin_addr));
send(consocket, msg1, strlen(msg1), 0);
close(consocket); // THIS IS THE IMPORTANT LINE
consocket = accept(mysocket, (struct sockaddr *)&dest, &socksize);
printf("Value X is: %s\n", msg1);
printf(" \r");
fflush(stdout);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment