I want to pass message between two devices, for an example devices are PCs. Currently I am using UDPServer.c and UDPClient.c for reference. By using this reference, I can pass messages, now I want to implement both side listen and send, also I want to create an API for sending message, that API can be used by other functions. May I need to use two different port for sending message and receiving message?? what is the best way to set up UDP socket programming for message passing??
-
Can you be more specific? Is it chat? File transfer? I'm not a socket guy, but I assume that there are lots of open source APIs using different port configurations depending on what you're doing. You might be able to adapt one to your needs or learn from the source.hellork– hellork2012-04-02 07:44:08 +00:00Commented Apr 2, 2012 at 7:44
-
Message passing only. Can you please list out API for C language?Nimit– Nimit2012-04-02 08:12:40 +00:00Commented Apr 2, 2012 at 8:12
Add a comment
|
1 Answer
From your description, it doesn't look like you need any more than what sendto()/recvfrom() already do. You might as well treat them as your "API" for message passing. Once you set up/open the socket, just send/recv as needed. You don't need to worry about different ports for sending/receiving; your example is fine. FYI, you can sendto/recvfrom on the same socket.