Is it possible to send a broadcast message over LAN
with SDL_net ?
(I’m using net2… but it’s the same)
I’d like to improve my little game, in which I use TCP
messages for implementing the network part…
and I’d like to know if (and how) I can send
a broadcast message (over a specified port) to
check the servers awaiting connections…–
SkunkGuru.
As far as I know, your need to use UDP/IP. Then yes,
you just send a packet to 255.255.255.255, and it will
be broadcasted to the LAN.
I programmed all my games network systems using UDP.
I don’t think there is a way to do broadacst with
TCP, because TCP is a point-to-point based sytem.
Maybe you can open a port only for this server
detection.
I don’t know what is “net2”. Some code need to be added
to broadcast. I know SDL_net has it, because I added it
SkunkGuru wrote:> Is it possible to send a broadcast message over LAN
with SDL_net ?
(I’m using net2… but it’s the same)
I’d like to improve my little game, in which I use TCP
messages for implementing the network part…
and I’d like to know if (and how) I can send
a broadcast message (over a specified port) to
check the servers awaiting connections…
As far as I know, your need to use UDP/IP. Then yes,
you just send a packet to 255.255.255.255, and it will
be broadcasted to the LAN.
can you send a small code sample ?
i have try, but it doesn’t work
I programmed all my games network systems using UDP.
where can I find them ?
Here is one in GPL: http://glob2.ysagoon.com (please do not publish the link yet, it’s still alpha.)
Here is one sample out of it:
void MultiplayersHost::sendBroadcastLanGameHosting(Uint16 port, bool create)
{
UDPpacket *packet=SDLNet_AllocPacket(4);
assert(packet);
packet->channel=-1;
packet->address.host=INADDR_BROADCAST;
packet->address.port=SDL_SwapBE16(port);
packet->len=4;
packet->data[0]=BROADCAST_LAN_GAME_HOSTING;
packet->data[1]=create;
packet->data[2]=0;
packet->data[3]=0;
if (SDLNet_UDP_Send(socket, -1, packet)==1)
fprintf(logFile, “Successed to send a BROADCAST_LAN_GAME_HOSTING(%d) packet to port=(%d).\n”, create, port);
else
fprintf(logFile, “failed to send a BROADCAST_LAN_GAME_HOSTING(%d) packet to port=(%d)!\n”, create, port);
SDLNet_FreePacket(packet);
}>>I don’t know what is “net2”. Some code need to be added
to broadcast. I know SDL_net has it, because I added it
(in the client)
printf(“reception d’une invitation. ip:%x id: %s”, packet->host,
packet->data);
host is not a member of UDPpacket… i think it should be
packet->address.host
(in the server)
strcpy(packet->data,UDP_MSG);
packet->len=strlen(UDP_MSG)+1;
my compiler (VC++6) wants an additional header, like
for strcpy and strlen; I must add an explicit conversion:
strcpy((char*)packet->data,UDP_MSG);
to convert the unsigned char* of ->data in the standard char*
after this little changes… it seems to work!
thank you very much for your help!!!
maybe it’s time to rewrite it in english?
I think it may be better… I can’t understand what you wrote…
but the code is clear and working ;-)–
SkunkGuru.