Mercurial > hg > beaglert
diff core/UdpClient.cpp @ 53:6907e2177eb8 ultra-staging
Fixed bugs in Udp classes, updated tests
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 07 Jun 2015 14:58:34 +0100 |
parents | f5b5c648cd5d |
children | 3068421c0737 |
line wrap: on
line diff
--- a/core/UdpClient.cpp Wed May 20 18:07:16 2015 +0100 +++ b/core/UdpClient.cpp Sun Jun 07 14:58:34 2015 +0100 @@ -7,6 +7,9 @@ #include "../include/UdpClient.h" UdpClient::UdpClient(){ + outSocket=socket(AF_INET, SOCK_DGRAM, 0); + isSetPort=false; + isSetServer=false; enabled=false; } UdpClient::UdpClient(int aPort, const char* aServerName){ @@ -17,6 +20,8 @@ } setPort(aPort); setServer(aServerName); + isSetPort=true; + isSetServer=true; enabled=true; } UdpClient::~UdpClient(){ @@ -26,9 +31,17 @@ port=aPort; destinationServer.sin_port = htons(port); destinationServer.sin_family = AF_INET; + isSetPort=true; + if(isSetServer){ + enabled=true; + } }; void UdpClient::setServer(const char* aServerName){ inet_pton(AF_INET,aServerName,&destinationServer.sin_addr); + isSetServer=true; + if(isSetPort){ + enabled=true; + } }; int UdpClient::send(void * message, int size){ if(!enabled) @@ -36,8 +49,9 @@ unsigned int length; length=sizeof(struct sockaddr_in); int n=sendto(outSocket,message,size,0,(const struct sockaddr *)&destinationServer,length); - if (n < 0) + if (n < 0){ return n; + } return 1; };