<font size="2">
<p>I have tried to implement the solution you provided me, but there are some problems sending data and I have some questions about it:</p>
<p>--------</p>
<p>SERVER:</p>
<p>--------</p>
<p>Server socket creation doesn't return errors, but I'm not sure if I'm doing things right</p>
<p>--- Socket creation---</p>
<p>mySocket = socket(AF_INET, SOCK_RAW, VT_UDP_SOCK); </p>
<p>//SOCK_RAW for raw UDP traffic?</p>
<p>---SetSockOpt---</p>
<p>int reuseAddrOp = 1;</p>
<p>setsockopt(mySocket,SOL_SOCKET/*IPPROTO_UDP*/,SO_REUSEADDR,&reuseAddrOp,sizeof(reuseAddrOp))</p>
<p>//must I change option for IPPROTO_UDP or SOL_SOCKET?</p>
<p>---Bind---</p>
<p>sockaddr_in inAddress;</p>
<p>inAddress.sin_family = AF_INET; </p>
<p>inAddress.sin_port = htons(DEFAULT_PORT); //#define DEFAULT_PORT 1001</p>
<p>inAddress.sin_addr.s_addr = htonl(INADDR_ANY); </p>
<p>//is INADDR_ANY address right?</p>
<p>bind(mySocket,&inAddress,sizeof(inAddress));</p>
<p>---Listening thread---</p>
<p>...</p>
<p>do</p>
<p>{</p>
<p>FindServerRequestMessage fsr_msg;</p>
<p></p>
<p>//the sockaddr_in parameter is right? I want to listen any address...</p>
<p>int result = recvfrom(mySocket,&fsr_msg, sizeof(fsr_msg), 0, &inAddress, sizeof(inAddress));</p>
<p></p>
<p>if(result > 0)</p>
<p>{</p>
<p>//Get fsr_msg data and answer</p>
<p>}</p>
<p>}</p>
<p>while(1);</p>
<p></p>
<p></p>
<p>--------</p>
<p>CLIENT</p>
<p>-------- </p>
<p>The client sends a FindServersRequest message through the socket.</p>
<p>When I try to send data with the "sendto" function returns me a -1, but I don't know why...</p>
<p>---Socket creation---</p>
<p>Like the server</p>
<p>---SetSockOpt---</p>
<p>Like the server</p>
<p>---Bind---</p>
<p>Like the server</p>
<p>---Delivery---</p>
<p>sockaddr_in outAddress;</p>
<p>outAddress.sin_family = AF_INET; </p>
<p>outAddress.sin_port = htons(1001); </p>
<p>outAddress.sin_addr.s_addr = htonl(ENET_HOST_BROADCAST); // BROADCAST sending, is it ok?</p>
<p>sendto(mySocket,&fsr_msg, sizeof(fsr_msg),0,&outAddress,sizeof(outAddress));</p></font>