.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > Socket disposing after some time
 

Socket disposing after some time

Hi There,

i have an socket server and client , some how the listener socket is getting disposed after some time for some reason . is there any expiry period associated with the socket , how do i set/control the expiry period if any .

i am using Socket class of .net 2.0

the error ocuured was

Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.Socket.Send(Byte[] buffer)
at PubSub.ChannelListener.receive(String msg)

since the reference of this socket is in main class , i do not think this would be because GC is collecting it .

any suggestions/comments will be highly helpful.

Thanks
Deepak

Dee
  •  
Dee28
Yes, sockets may have timeouts associated with them.

However, reaching one of these timeouts is not going to Dispose the object. Something is calling Dispose, either your code or a library you call.

> i do not think this would be because GC is collecting it .

If the GC collects it, then you would not be able to access it to get the error you are showing. So the GC does not seem to be the problem.
BinaryCoder
Yes, sockets may have timeouts associated with them.

However, reaching one of these timeouts is not going to Dispose the object. Something is calling Dispose, either your code or a library you call.

> i do not think this would be because GC is collecting it .

If the GC collects it, then you would not be able to access it to get the error you are showing. So the GC does not seem to be the problem.
BinaryCoder
Hi Deepak
Do you still need help with your question? If you have figured out what was causing the problem, can you post it here so other people can benefit?
And if you're still seeing it can you post a code snippet and /or trace file?
Instructions are here:
http://blogs.msdn.com/ncl/archive/2008/07/25/how-to-troubleshoot-your-system-net-code.aspx


Thanks
Mariya
Mariya Atanasova [NCL]

You can use google to search for other answers

Custom Search

More Threads

• Setting up port forwarding with nat, using library NATUPNPLib, Null reference exception
• help!!!
• Send email on behalf of another user?
• Exchange SMTP .NET email issue.
• Send a mail with picture.
• ConnectAsync doesn't work with datagram sockets?
• Not receiving extended ASCII characters correctly on UDP socket
• FtpWebRequest - multi-threading issues
• check network path
• sample messages to write into a tcpclient networkstream?