[ENet-discuss] Broadcast Messages through the LAN - Trying an implementation
David Orejuela
david.orejuela.esteban at gmail.com
Wed Mar 18 03:07:56 PDT 2009
I have tried to implement the solution you provided me, but there are some
problems sending data and I have some questions about it:
--------
SERVER:
--------
Server socket creation doesn't return errors, but I'm not sure if I'm doing
things right
--- Socket creation---
mySocket = socket(AF_INET, SOCK_RAW, VT_UDP_SOCK);
//SOCK_RAW for raw UDP traffic?
---SetSockOpt---
int reuseAddrOp = 1;
setsockopt(mySocket,SOL_SOCKET/*IPPROTO_UDP*/,SO_REUSEADDR,&reuseAddrOp,sizeof(reuseAddrOp))
//must I change option for IPPROTO_UDP or SOL_SOCKET?
---Bind---
sockaddr_in inAddress;
inAddress.sin_family = AF_INET;
inAddress.sin_port = htons(DEFAULT_PORT); //#define DEFAULT_PORT 1001
inAddress.sin_addr.s_addr = htonl(INADDR_ANY);
//is INADDR_ANY address right?
bind(mySocket,&inAddress,sizeof(inAddress));
---Listening thread---
...
do
{
FindServerRequestMessage fsr_msg;
//the sockaddr_in parameter is right? I want to listen any address...
int result = recvfrom(mySocket,&fsr_msg, sizeof(fsr_msg), 0, &inAddress,
sizeof(inAddress));
if(result > 0)
{
//Get fsr_msg data and answer
}
}
while(1);
--------
CLIENT
--------
The client sends a FindServersRequest message through the socket.
When I try to send data with the "sendto" function returns me a -1, but I
don't know why...
---Socket creation---
Like the server
---SetSockOpt---
Like the server
---Bind---
Like the server
---Delivery---
sockaddr_in outAddress;
outAddress.sin_family = AF_INET;
outAddress.sin_port = htons(1001);
outAddress.sin_addr.s_addr = htonl(ENET_HOST_BROADCAST); // BROADCAST
sending, is it ok?
sendto(mySocket,&fsr_msg, sizeof(fsr_msg),0,&outAddress,sizeof(outAddress));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20090318/0fff2735/attachment.htm>
More information about the ENet-discuss
mailing list