Re: SetSockOpt with SO_REUSEADDR parameter
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 23 Mar 2007 04:06:18 -0500
He really doesn't get the fact that his basic premise is nonsensical. THere is simply no
supported concept anywhere in the network stack of creating multiple sockets with the same
port #; the concept does not exist, and his workaround is doing something that does not
make sense. His code gives the illusion of working because he forces it to bypass a
legitimate error message, so he doesn't get an error message because of his erroneous
code. The only way to fix this is to rewrite the code to make sense. It currently
doesn't.
If he is using UDP to send, then there is ONE UDP socket to do this, and all the
connections send messages via this one-and-only UDP port. What I would do here is create
a sender thread and queue up messages for it to send; avoids all kinds of nasty problems
with synchronization between threads.
joe
On Fri, 23 Mar 2007 08:05:49 +0100, Norbert Unterberg <nunterberg@xxxxxxxxxxxxxxxxx>
wrote:
mmlab_js schrieb:Joseph M. Newcomer [MVP]
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?
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. 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.
==========================================
BOOL CUdpSendSocket::Create(UINT nSocketPort, int nSocketType, long lEvent,
LPCTSTR lpszSocketAddress)
{
if (Socket(nSocketType, lEvent))
{
BOOL bMultipleApps = TRUE;
SetSockOpt(SO_REUSEADDR, (void*)&bMultipleApps, sizeof(BOOL),
SOL_SOCKET);
You are still doing things with UDP and sockets here what they are not designed for.
Norbert
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Re: SetSockOpt with SO_REUSEADDR parameter
- From: Joseph M . Newcomer
- Re: SetSockOpt with SO_REUSEADDR parameter
- From: mmlab_js
- Re: SetSockOpt with SO_REUSEADDR parameter
- From: Norbert Unterberg
- Re: SetSockOpt with SO_REUSEADDR parameter
- From: Norbert Unterberg
- Re: SetSockOpt with SO_REUSEADDR parameter
- Prev by Date: Re: Alternative to 'AfxSetResourceHandle'
- Next by Date: solved . code is not the same to the DLL.
- Previous by thread: Re: SetSockOpt with SO_REUSEADDR parameter
- Next by thread: Re: SetSockOpt with SO_REUSEADDR parameter
- Index(es):
Relevant Pages
|