Re: SetSockOpt with SO_REUSEADDR parameter

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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:

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
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: SMTP and tcp ports
    ... This ACL would permit access to the internal SMTP server (listening on TCP port 25) from external clients and servers. ... The mail clients would be using a TCP source port>1023, and external mail servers would be using TCP source port 25, or TCP source port>1023. ...
    (comp.dcom.sys.cisco)
  • Re: Definition of a socket on Suns website
    ... the server gets a new socket bound to a different port. ... It needs a new socket (and consequently a different port number) so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client. ...
    (comp.lang.java.programmer)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... overlapped sockets with an I/O Completion Port. ...
    (microsoft.public.vc.language)
  • Re: millionth socket problem....
    ... > my client *is* working. ... > My server is the following, ... > use Socket; ... Your program worked for me, if I changed the port number to 7023, as ...
    (perl.beginners)
  • RE: SBS2K3 Prem Symantec Security Gaeway
    ... Destination Port: 500 ... Source Port: 49152-50151 (if Dynamic ISAKMP Source port is enabled in ... Configure ISA server to pass the following inbound protocol for rekey events ... Microsoft is providing this information as a convenience to you. ...
    (microsoft.public.windows.server.sbs)