Overlappingsocket - UDP trouble
Hi
Im using overlapping sockets to send UDP packets. This is my first time using UDP in winsock2.2 and I dont understand some things.
Does both sides have to bind? If the client have to bind what port do i bind to, I want to bind to the port im sending on, how can I get that portnumber im sending on?
Yes, both the client and server have to bind.
You decide what ports to bind to.
You have to send to the port the other side is bound on.
You have to decide how you''ll know what port to use; udp has a source and destination port in the header, you usually use the source port to tell the other side what port you are bound to.
You decide what ports to bind to.
You have to send to the port the other side is bound on.
You have to decide how you''ll know what port to use; udp has a source and destination port in the header, you usually use the source port to tell the other side what port you are bound to.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
> Does both sides have to bind?
No. The server needs to bind in order for clients to find it, but there is no such restriction on the client side since it is the one that initiates the communication. The server can pick up the port and IP of the sending client from the 'recvfrom()' API call and simply 'sendto()' the IP and port it got.
> how can I get that portnumber im sending on?
'getsockname()' will return you the port the socket is currently bound to locally, regardless if you explicitely bound it yourself or leave the OS do it for you.
-cb
EDIT: On Windows, recvfrom() should be WSARecvFrom() and sendto() should be WSASendTo() because you are using overlapped I/O.
[edited by - cbenoi1 on January 17, 2004 5:10:38 PM]
No. The server needs to bind in order for clients to find it, but there is no such restriction on the client side since it is the one that initiates the communication. The server can pick up the port and IP of the sending client from the 'recvfrom()' API call and simply 'sendto()' the IP and port it got.
> how can I get that portnumber im sending on?
'getsockname()' will return you the port the socket is currently bound to locally, regardless if you explicitely bound it yourself or leave the OS do it for you.
-cb
EDIT: On Windows, recvfrom() should be WSARecvFrom() and sendto() should be WSASendTo() because you are using overlapped I/O.
[edited by - cbenoi1 on January 17, 2004 5:10:38 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement