Community discussion forum

Problem related to socket program in VB.NET

  • 2 months 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...

    Post was edited on 05/09/2009 07:29:51 Report abuse
  • 2 months 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).

We'd love to hear what you think! Submit ideas or give us feedback