Re: SetSockOpt with SO_REUSEADDR parameter



mmlab_js schrieb:

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.

That is basically fine. You just overlooked that there is no need to use the same port number on both ends of the "connection". The clients creates a socket on a spefific port number. The server creates a socket on ANY port number, but it uses the client's port number as destination port when sending the data.

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???

Well, I think I was wrong on that one. Sorry for confusing you.
The accept call creates a new socket with the same local port number. The difference is, that this socket is not in an unconnected (listening) state.

There can only be one listening socket on any local port number.

The problem with UDP is that UDP does not have connections. So all sockets you create and bind to a port are always listening sockets.
That's why you can only have one UDP socket per port number.

Norbert
.



Relevant Pages

  • Re: UDP source port number when using RAW socket??
    ... the source port in a UDP packet is an *optional* ... If you *do* expect UDP packets in reply to the packets you send out, ... then what you really want to do is open a plain UDP socket and bind ... Use your raw socket to send out packets and your UDP socket to receive ...
    (comp.os.linux.development.system)
  • Re: SetSockOpt with SO_REUSEADDR parameter
    ... no concept that allows you to create multipe sockets with the same port number. ... happening is that you are throwing away the old socket and replacing it with the new ... That is not the same as creating multiple sockets with the same port #. ... Because I will send real-time video frame, I use UDP socket. ...
    (microsoft.public.vc.mfc)
  • Re: Possible bug in .Net 2.0 udp sockets?
    ... assumption that the port which the client sees is the same as the port ... this way when hundreds of clients are connected; ... With IOCP that is. ... guarantee that when you call BeginReceiveFrom using a UDP socket, ...
    (microsoft.public.dotnet.framework)
  • Re: Problem with socket
    ... Be aware that those port numbers are part of the IANA-assigned range. ... socket operations on sockets for which there are no handles... ... The result of using comma lists is ... you have used the completely meaningless word "crash" to describe your ...
    (microsoft.public.vc.mfc)
  • RE: call is blocked in recvfrom() and no further proceedings in Win CE
    ... In windows CE, I'm able to send a request but I'm unable to receive it. ... Create another socket & bind with server IP address. ... > My program has to send request to service through port 5070(in this port only ...
    (microsoft.public.windowsce.embedded)