Re: SetSockOpt with SO_REUSEADDR parameter
mmlab_js schrieb:
I override the CASyncSocket::Create to solve this problem.
Why is it so important to you to use the SAME source port number for all
clients? What is the *real* problem you are trying to solve? I simply do not
believe your boss told you to use the same server socket and port number for all
client streaming data. So what is the real issue?
I construct a streaming server that sending a real-time frame captured from
webcam to clients who login in. At first, because I don't know how to write a
server-client architecture, I reference
[http://support.microsoft.com/kb/192570]. At second, I want to add the UDP
socket into this architecture to send real-time frames. So, I add UDP socket
into CServerThread class and create it at
===============================================
BOOL CServerThread::InitInstance()
{
UINT dummy;
m_socket.GetPeerName(m_UdpSocket.m_strClientAddress, dummy);
m_UdpSocket.CreateSocket(DATA_PORT);
return TRUE;
}
===============================================
The client application create a UDP socket with the same port DATA_PORT and
it can get the real-time frame from server. That's my original idea.
Usually, when doing things liek this and I need one socket per "connection",
then I bind the local socket to PORT_ANY because I do not care. WHat is
important is that the destination port number is correct, usually not the source
port number.
When using TCP, the source port number is usually totally irrelevant, what
counts is the destination port when creating a connection. When a server accepts
a TCP connection, a new socket is created with a totally new and unrelated
server port number.
When a server accepts a TCP connection, a new socket is created with a
"unused" port on server. So, every sockets will use different ports. Right???
Why do you insist on using the same server port number for
all your UDP traffic when even TCP does not do it that way?
Do you really understand the concept of source and destination port number, the
difference between these two, and how TCP and UDP handle them?
The client can detect whether a received packet comes from the correct server by
looking at the source address in this case. If you really need to check the
source port, then tell the client the automatically generated port number over
the TCP control connection that the server seems to haver to the client.
I will re-study again.