Home » Community » Newbie corner » UDP connection
Re: UDP connection [message #36026 is a reply to message #36023] |
Thu, 19 April 2012 20:32 |
Zbych
Messages: 326 Registered: July 2009
|
Senior Member |
|
|
There are two packages in bazaar: UrrPingClient and UrrPingServer.
Here you have simple Linux udp server. On windows you need to add some winsock initialization.
#include <Core/Core.h>
#include <arpa/inet.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sock < 0) {
RLOG("SOCK ERROR");
return;
}
sockaddr_in srvadr;
srvadr.sin_family = AF_INET;
srvadr.sin_port = htons(9999);
srvadr.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(sock, (sockaddr *) &srvadr, sizeof(srvadr)) != 0) {
RLOG("SOCK BIND ERROR");
close(sock);
return;
}
struct sockaddr addr;
socklen_t addr_size = sizeof(addr);
char buff[256];
while(1){
ssize_t len = recvfrom(sock, buff, sizeof(buff), 0, &addr, &addr_size);
if (len > 0){
Cout() << Format("%d.%d.%d.%d: '%s'",
addr.sa_data[2], addr.sa_data[3], addr.sa_data[4], addr.sa_data[5], String(buff, len));
}
}
close(sock);
}
|
|
|
|
|
UDP connection
By: Wolfgang on Wed, 18 April 2012 10:00
|
|
|
Re: UDP connection
By: Zbych on Wed, 18 April 2012 10:10
|
|
|
Re: UDP connection
By: Wolfgang on Thu, 19 April 2012 14:59
|
|
|
Re: UDP connection
By: Zbych on Thu, 19 April 2012 15:25
|
|
|
Re: UDP connection
By: Wolfgang on Thu, 19 April 2012 16:03
|
|
|
Re: UDP connection
By: Zbych on Thu, 19 April 2012 20:32
|
|
|
Re: UDP connection
By: Wolfgang on Thu, 19 April 2012 21:24
|
|
|
Re: UDP connection
By: Zbych on Fri, 20 April 2012 08:14
|
|
|
Re: UDP connection
By: Wolfgang on Fri, 20 April 2012 09:34
|
|
|
Re: UDP connection
By: Zbych on Fri, 20 April 2012 10:16
|
|
|
Re: UDP connection
By: Wolfgang on Fri, 20 April 2012 10:23
|
Goto Forum:
Current Time: Wed May 08 11:26:12 CEST 2024
Total time taken to generate the page: 0.02905 seconds
|