[SDL] SDL_net and broadcasting
nuage at ysagoon.com
Mon Sep 30 04:58:01 PDT 2002
>>IIRC, anything ending in .255 is a broadcast address. If your subnet is
>>128.0.0, sending to 188.8.131.52 should broadcast to the entire network
>>- assuming the network allows IP broadcast.
>>However, I don't know if this will work with SDL_net. You may have to
>>use a UDP packet instead of TCP.
TCP is a connected transmission protocol, one socket to one socket.
Then you can't have any broadasting ability with TCP. (only multicasting
but this is something totally different we won't talk about)
So you can only broadcast with UDP packets.
yes, any address ending with .255 is a broadcasting address.
>SDL_net provides UDP packets, and yes, I believe Darrell is correct.
>Does Linux require extra work to send to the broadcast addresses?
Yes you need extra work, somhow.
You can't simply send packets to a broadcasting address. This will fail.
A SDL_net example:
void f(int size, void *data)
memcpy((char *)packet->data, data, size);
bool success=SDLNet_UDP_Send(socket, channel, packet)==1;
Or a UNIX example:
// servAddr has been set to 255.255.255.255
int rc=sendto(socketDefinition, data, size, 0, (struct sockaddr *)
You have to modiffy the "socketDefinition" this way:
("sock->channel" into SDLnetUDP.c)
setsockopt(socketDefinition, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
setsockopt(socketDefinition, SOL_SOCKET, SO_BROADCAST, &hold, sizeof(hold));
OK, setting TTL=1 is obviously optional, but cleaner.
But the second modiffication is mandatory for broadcasting.
Once it's accepeted, we have to come back to my fist mail: how to
implements this ?
Luc-Olivier de Charrière
More information about the SDL