After server, which is listening on port X, receives a request from the client, can it send response from a different process and a socket with sendto call. Please note that the client also sends request with sendto (server address) call.
Here are the steps:
- server opens a socket and binds it to IP address (a.b.c.d) and port (x)
- client opens a socket and binds it to IP address (k.l.m.n) and port (z) and sends request to server with sendto call.
- Server (in different process) opens a socket and binds it to IP address (a.b.c.d) and port (y)
- server sends response from above socket to client with sendto
Both client and server knows each other ip addresses and port numbers.
I am noticing that client does not receive response when server sends response from a different process. Otherwise, it does.
TCP
oriented, you can spawn a child process and the file descriptor of the accepted connection will be inherited. Then usesend()
andrecv()
. But it seems you are using UDP sockets. InUDP
sockets, you only create the socket and bind to it. There's nolisten()
ing port. You then usesendto()
andrecvfrom()
. In your case, you should spawn a child, which already inherited the creation and binding to socket, torecvfrom()
the messages sent from client. If you are truly creating, binding and listening on a connection oriented,sendto()
ignores the destaddr – alvitssendto()
even in connection oriented socket but you need to userecv()
. In connectionless oriented socket you can only usesendto()
andrecvfrom()
. – alvits