Problem related to socket program in VB.NET

3.5 Framework , Windows 2003 Server , VB.NET India
  • 8 years ago

    Hye friends,

    I am facing one issue related to socket program written in VB.NET (2008 + 3.5 framework) since long time....I am having a socket server application which accepts the connection...It accepts 800 connection without any problem but after that it throws exception saying...."Exception of type 'System.OutOfMemoryException' was thrown. : mscorlib : 0" After this exceptions it stops accepting any further connections even if all the connected clients gets disconnected. Same case happens if single client continuously connects & disconnects at an interval of 3 sec. After 2 hrs. it throws same exeption. I am using Windows 2003 server + 2 GB RAM. If anyone faced same problem pls help...

  • 8 years ago

    I had a similar problem in an application that used the .Net 2.0 framework. References to an IAsyncResult object were preventing the GC from collecting it. And the IAsyncResult AsyncWaitHandle needed to be closed. The following snippets of code show what I did to fix the problem.

        socket.BeginAccept(new AsyncCallback(OnConnectionMade), socket);
    
        private void OnConnectionMade(IAsyncResult asyn)
        {
            try
            {
                // complete connection and get socket object
                Socket soc = ((Socket)asyn.AsyncState).EndAccept(asyn);
                // recover resources
                asyn.AsyncWaitHandle.Close();
    

    I hope this helps.

    Steve

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan