Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - gturi

Pages: [1]
1
Network / Problem when broadcast with UDP socket
« on: August 22, 2009, 07:58:36 am »
My problem is i couldn't received the packet that was broadcasted before
Here are my codes:
* When send broadcast packets:
Code: [Select]
sf::Packet BroadcastPacket;
BroadcastPacket<<"Hello world";
sf::IPAddress BroadcastAddress = "255.255.255.255";
unsigned int BroadcastPort = 26385;
m_Socket.Send(BroadcastPacket, BroadcastAddress, BroadcastPort);

* To receiving with sf::packet:
Code: [Select]
sf::Packet packet;// = sf::Packet();
sf::IPAddress ip;
unsigned int port = 26385;
m_SockUdp.Bind(port);
sf::Socket::Status sockStatus = this->m_SockUdp->Receive(packet, ip, port);
if(sockStatus == sf::Socket::Status::Done)
{
///some code here
///...

}

with these codes, packet always return size 0, though the sockStatus return Done
* When i try to receive with char array:
Code: [Select]

sf::IPAddress ip;
unsigned int port = 26385;
m_SockUdp.Bind(port);
size_t size;
char buf[1024];
sf::Socket::Status sockStatus = this->m_SockUdp->Receive(buf, 1024, size,ip, port );
if(sockStatus == sf::Socket::Status::Done)
{
///some code here
///...

}

i received exactly the broadcast data.

* What i don't make sence is why i can't received broadcast data in sf::packet? Or did i do some thing wrong when broadcast?
If you have done it before please give me an example to broadcast with udp socket. Any opinion is appreciated.
I used sfml 1.5 for windows, the same problem with sfml 1.4
* another question: how can i get the socket error number? sf::Socket::Status only has Error value, but i want to get the error code.

Thank you very much

Pages: [1]