Re: SocketException: Too many open files - can't understand why though?
- From: "Lee" <lvturner@xxxxxxxxx>
- Date: 13 Dec 2006 11:12:28 -0800
Humm, sorry it is tab-indented here... guess it got lost in the post
somehow.
To clear things up, this class isn't instantiated when mouse move is
called, only it's 'sendData' method is called then.
The reason I'm not using TcpClient class is because, well, this is
merely a wrapper to it, to encapsulate reciving data and have an
appropriate event triggered.
If required I could re-post this class onto a paste-bin and hopefully
tab indenting would be preserved?
Peter Duniho wrote:
"Lee" <lvturner@xxxxxxxxx> wrote in message
news:1166034110.605508.313360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[...]
System.Net.Sockets.SocketException: Too many open files
at System.Net.Sockets.Socket..ctor (AddressFamily family, SocketType
type, ProtocolType proto) [0x00000]
at System.Net.Sockets.TcpClient.Init (AddressFamily family) [0x00000]
at System.Net.Sockets.TcpClient..ctor () [0x00000]
at FINN.DataEventArgs..ctor (System.String data) [0x00000]
at FINN.frmGame.picMainDrawArea_mouseMove (System.Object sender,
System.Windows.Forms.MouseEventArgs e) [0x00000]
at (wrapper delegate-invoke)
[...]
I really can't figure out why this is occuring and was wondering if
anyone was able to help me improve my code and show me where it's wrong
(and why!) so that I can stop this from occuring.
Just a guess, but I suspect that you have too many files open.
It's hard for me to read the code you posted, as there's no indentation at
all, and it's not clear that you've actually posted a good sample (e.g.
minimal code required to *fully* reproduce the issue). However, creating a
TcpClient inside your mouse-move event handler is a little odd. Mouse-moves
happen all the time...I don't see any legitimate reason to create a new
TcpClient each time one happens, even if one does assume that those
TcpClients are properly cleaned up (and given the error you're getting, it
seems they may not be).
So, rather than creating a new TcpClient every time you instantiate a
DataEventArgs, perhaps it would be better for you to create a TcpClient
once, and then supply that to the DataEventArgs constructor, or otherwise
gain access to it.
I suppose you could keep doing it the way you're doing it now, as long as
you added an explicit Close/Dispose method to the DataEventArgs class and
called that everywhere that you create a DataEventArgs and then are done
using it. But that's a pain, and it ignores the fact that creating a new
TcpClient every time you move the mouse is still a bad idea.
Pete
.
- Follow-Ups:
- Re: SocketException: Too many open files - can't understand why though?
- From: Peter Duniho
- Re: SocketException: Too many open files - can't understand why though?
- References:
- Prev by Date: Re: IDisposable or not in custom classes
- Next by Date: Re: Taking a single large .cs file and making many smaller .cs files
- Previous by thread: Re: SocketException: Too many open files - can't understand why though?
- Next by thread: Re: SocketException: Too many open files - can't understand why though?
- Index(es):
Relevant Pages
|