Properly terminating socket connection
Properly terminating socket connection
Properly terminating socket connection
Properly terminating socket connection
Properly terminating socket connection
Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection
Properly terminating socket connection Properly terminating socket connection
Properly terminating socket connection
Go Back  Xtreme Visual Basic Talk > > > Properly terminating socket connection


Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2008, 12:08 AM
Al Capwn Al Capwn is offline
Newcomer
 
Join Date: May 2008
Posts: 2
Default Properly terminating socket connection


Hello everyone, I am starting to create an online multiplayer game which I have started to build as a basic chat lobby. I have server and client applications and everything is working well except for disconnection.

How do I properly close a socket connection between client and server applications user System.Net.Sockets so that the socket can be used again afterwards?

Both my client and server applications have a System.Net.Sockets.TcpClient() and a NetworkStream, and my server has a TcpListener as well... but Im pretty sure the listener needs to stay there to wait for connections.

I see .close and .client.close and .client.disconnect and .client.shutdown and a whole bunch of crap like that but I can't seem to get everything to work together. I assume SOMEONE has properly made a socket communicating client/server program before so this CAN be done.

I keep getting exceptions because my server tries to use the connection to the client after the application closes.
Reply With Quote
  #2  
Old 05-26-2008, 08:53 AM
Al Capwn Al Capwn is offline
Newcomer
 
Join Date: May 2008
Posts: 2
Default

When I try to reconnect, whether I closed and reopened the client or disconnected using clientsocket.close(), I get the exception "Cannot access disposed object. Object name: System.Net.Socket.TcpClient". clientSocket is my TcpClient object and I get the error when I try clientsocket.connect after I have already disconnected.
Reply With Quote
  #3  
Old 08-31-2010, 12:29 PM
mtoibero mtoibero is offline
Newcomer
 
Join Date: Nov 2009
Posts: 1
Default

Same problem. and if you try to use the same socket, you receive a "a connect request was made on an already connected socket"
which is the right way?
Reply With Quote
  #4  
Old 09-28-2010, 08:12 AM
PrOpHeT's Avatar
PrOpHeTProperly terminating socket connection PrOpHeT is offline
Hopelessly confused...

* Expert *
 
Join Date: Mar 2001
Location: Tyler, Tx.
Posts: 3,055
Default

The proper method of handling this would not be to close the original socket..
when handling the incoming request pass the load to a second socket leaving the original one open to listen for more incoming connections.

I have a fully functional multi threaded TCP server if you would like a sample.

It is rather generic and I could comment out my application specific needs if you would like to take a look.

IMHO it is like providing a flamethrower where one has requested a match, however it would take a long time to explain all of the concepts of a multi threaded TCP server without the code to look at.

You will find many examples of how to code your own connection loop and handle the threading, however my example uses the existing async methods of the TCP client.
Attached Files
File Type: txt TCPClientWrapper.txt (17.2 KB, 42 views)
File Type: txt TCPServer.txt (18.6 KB, 17 views)
__________________
When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do ;)

For the love of Gold...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Properly terminating socket connection
Properly terminating socket connection
Properly terminating socket connection Properly terminating socket connection
Properly terminating socket connection
Properly terminating socket connection
Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection Properly terminating socket connection
Properly terminating socket connection
Properly terminating socket connection
 
Properly terminating socket connection
Properly terminating socket connection
 
-->