RE: TCP Cannot close my socket directly.... without reason ?

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



How about a udp socket and a tcp socket?
They can be used together.

“Chris”编写:

Hello everybody,

(I have already do this post, but after a while the previous solution was
not good, so I repost in the forum, sorry)

I contact you because I have some problems with TCP... I have try to find a
solutions, but I cannot find the problem. Maybe I have miss something.

I explain my problem... Here is what my client is doing.

Connection 1
------------
1 - On the client, I create a first socket that is "binded" to port 8900 and
I start the "Accept" on it.
(Yes, my client is also a server)
2 - I create a new "second" socket, bind it to port 8900 (Yes the same port,
I use REUSE_ADDRESS). And I connect to the server.

After this I have a Server and a client socket binded on the same port. It
is because my server
must send me the IP and port of the first socket as seen on the public IP
addresses (behind the NAT).

3 - I close the 2 sockets

Connection 2
------------
1 - On the client, I create a first socket that is "binded" to port 8900 and
I start the "Accept" on it.
(Yes, my client is also a server)
2 - I create a new "second" socket, bind it to port 8900 (Yes the same port,
I use REUSE_ADDRESS). And I connect to the server.

then.....

I got an error "10048" that tell me "Only one usage of each socket address
(protocol/network address/port) is normally permitted".

So I have try this :
1 - I have put Linger to on with a delay of 15 seconds (code is in C#....
but you should understand)

LingerOption lingerOption = new LingerOption(true, 15); // 15 seconds
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger,
lingerOption);

2 - I have use ReuseAddress :
socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress, 1);


Note: If for the second socket I do not bind to the same port, I have no
problem.
I m sure you have understand that I m trying to do the "NAT Hole Punching"
technique ;-)


But.... I can find a way to solve this !!!!! Can you help me, maybe you
already have an idea ?

Thanks for your help, really I appreciate

With Regards



.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: socket communication: socket doesnt connect
    ... Microsoft MVP, MCSD ... As far as your server code goes, ... accept the listening socket. ... Client client = new Client; ...
    (microsoft.public.vc.language)
  • Re: TCP server stop receiving new connections
    ... reset the event mask of your listening socket each time you ... I have a strange problem in my class library used by all our client ... server applications. ... incomming connections, but keeps current connections. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)