Re: SetSockOpt with SO_REUSEADDR parameter



****
This concept does not exist. So whatever you are trying to do, it won't work. There is
no concept that allows you to create multipe sockets with the same port number. What is
happening is that you are throwing away the old socket and replacing it with the new
socket.
****

I write a server application to send real-time video frame to client(s).
When a client logins into server, I will create a UDP socket to send
real-time video frame to it.
So, I think I will use multiple sockets with the same port to send frame.
Is this concept wrong?

****
NEVER, EVER, UNDER ANY CIRCUMSTANCES IMAGINABLE, EVER WRITE SOMETHING LIKE THIS!
THIS IS ALWAYS AN ERROR!!!
It make no sense at all to compare a boolean value to TRUE or FALSE; it is as pointless as writing
if( (a > 0) == TRUE)
instead of writing
if(a > 0)
since a boolean value always stands for, well, a boolean value. Comparing a boolean value
to TRUE is ALWAYS an error, since ANY non-zero value is non-FALSE, but you have
erroneously insisted that it be equal to the literal TRUE!

LOSE THIS BAD PROGRAMMING STYLE IMMEDIATELY!!!!
*****
Thanks for your suggestions. I will remember and change my bad programming
style.

I'm not sure what you are doing here or why you are needing to reuse the address for
multiple connections, because UDP is a connectionless protocol.
The reason I use mutiple UDP is the beginning of this response.
Because I will send real-time video frame, I use UDP socket.
I will re-describe my idea. The basic architecture is based on the source
[http://support.microsoft.com/kb/192570]
1) Server listen on port 9898
2) Client spawns a thread, which connects to the server
3) Server accepts the connection and spawns a thread to handle the socket
communication and send real-time frame
4) The thread creates a UDP socket with port 9899
5) The thread sends the real-time frame with UDP socket to client.
So, I think I need one UDP socket for one client.

After I change the following code:
==============================================================
void CUdpSendSocket::CreateSocket(UINT nPort)
{
CString szError;

BOOL bRet = Create(nPort, SOCK_DGRAM, FD_WRITE);

if (bRet > 0) {
szError.Format(_T("Send Socket Create() failed: %d"), ::GetLastError());
AfxMessageBox(szError);
return;
}
m_nPortNum = nPort;

BOOL reuse = TRUE;
if (!SetSockOpt(SO_REUSEADDR ,&reuse, sizeof(int))) {
szError.Format(_T("SetSockOpt failed to set SO_REUSEADDR:%d"),
::GetLastError());
AfxMessageBox (szError);
}
}
==============================================================
It still can't work for create UDP sockets with the same port. What shall I
do?
.



Relevant Pages

  • 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: Howto find multiple servers using TCP
    ... You will have to create a UDP socket ... When a packet is sent using a UDP socket ... differences between multicast and regular udp packets, ... But if the server program is your program, ...
    (microsoft.public.vc.mfc)
  • 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
    ... When a client logins into server, I will create a UDP socket to send real-time video frame to it. ... This endpoint is described by the local machine's IP address and a local port number. ... When you refer to "connect" here I assume you mean that the client calls a function named Connect. ...
    (microsoft.public.vc.mfc)
  • Re: Error binding socket: address already in use
    ... SOCK_DGRAM, IPPROTO_UDP), leaves the socket in an unclosed state. ... If you are seeing UDP sockets remain open when you kill a server make ... Additional note on REUSEADDR: The standard semantics of REUSEADDR on a ... UDP socket is to allow several sockets to bind to the same address ...
    (Linux-Kernel)