recvfrom_ signature and use
BlitzMax Forums/BlitzMax Programming/recvfrom_ signature and use
| ||
Okay, so I am working on a little peer to peer code for fun. I decided to use UDP (pretty obvious), and I need to know the source of messages sent to a node. So I can't use streams, which allow me to do everything but that. Anyway, I got some code from the forums, it looks like the recommended way to do this is to use recvfrom_. Here is my question: All of the code samples I can find (68756, 62117, 68758, 61507) seem to use this signature for recvfrom_: recvfrom_(socket, buffer, buffer_length , flags, senderip, senderport ) However the MSDN page for recvfrom (which I can only assume is the same function, since recvfrom_ is refered to frequently as a system call, API, etc.) has this signature: int recvfrom( SOCKET s, char* buf, int len, int flags, struct sockaddr* from, int* fromlen ); The remarks for from and fromlen are: from [out] Optional pointer to a buffer in a sockaddr structure that will hold the source address upon return. fromlen [in, out] Optional pointer to the size, in bytes, of the from buffer. This is, to say the least, not what people have been writing. What's going on? |
| ||
Function recvfrom_ in stdC.bmx has arguments :Function recvfrom_( socket,buf:Byte Ptr,size,flags,sender_ip Var,sender_port Var) This function calls stdc.c which contains int recvfrom_( int socket,char *buf,int size,int flags,int *_ip,int *_port){ This function then calls the API Recvfrom count=recvfrom(socket,buf,size,flags,(void*)&sa,&sasize); which matches the documentation you point to. |
| ||
Update: Updated code to working version. Super! Just wanted to make sure I wasn't loosing my mind. I didn't even notice the stdC module before. So here's what I've got so far. It isn't exactly working though; strangely, even though I have two sockets open, it reads the last bit of data that it sent. I probably missed something in conversion from using streams. Yes, this is a total hack. Start two of them up, and enter /connect localhost #### Replacing the #### with the port number that the other instance reported. Then enter anything (that doesn't start with a / or ^) in either window and it is supposed to show up in the other. peer.bmx Can't find where I got this, it was on the forum somewhere, the function was originally called "SmartSplit" if I recall correctly: lib/strings.bmx |
| ||
Just updated the code for peer.bmx. Works now, basically. I need to think about it a bit more - each node sends UDP messages directly to each other node. For my purposes this will probably work. |