Skip to content

Instantly share code, notes, and snippets.

@adammika
Created October 21, 2008 03:52
Show Gist options
  • Save adammika/18245 to your computer and use it in GitHub Desktop.
Save adammika/18245 to your computer and use it in GitHub Desktop.
for (int i = 0; i < (int)peers.size(); i++) {
char* peer;
bzero((char *) &peer, sizeof(peer));
peer = peers.at(i);
char* ip = strtok(peer," ");
char* port = strtok(NULL," ");
server_address.sin_port = htons(atoi(port));
if (inet_pton(AF_INET,ip,&server_address.sin_addr) != 0) {
ostringstream xval;
xval << posx;
ostringstream yval;
yval << posy;
ostringstream frame;
frame << framestamp;
string message = "POSX " + xval.str() + "\nPOSY " + yval.str() + "\nCOLOR " + color + "\nNAME " + name + "\nFRAMESTAMP " + frame.str();
if (sendto(socketfd,message.c_str(),sizeof(message),0,(struct sockaddr *)&server_address,sizeof(server_address)) == -1) {
cout << "Error sending UDP packet out" << endl;
} else cout << "Message sent!" << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment