Not logged in. · Lost password · Register
Forum: agsXMPP RSS
sockets
Avatar
Rotjoeng #1
Member since Jul 2006 · 14 posts
Group memberships: Members
Show profile · Link to this post
Subject: Unable to write data to the transport connection: Cannot access a disposed object.
Hi,

I need some help here.

I keep on getting this error:

Unable to write data to the transport connection: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'..

@ Send Member of ClientSocket
if (m_PendingSend)
m_SendQueue.Enqueue(bData);
else
{              
     m_PendingSend = true;
     m_NetworkStream.BeginWrite(bData, 0, bData.Length, new AsyncCallback(EndSend), null);
}

When debugging and placing a breakpoint just before "m_NetworkStream.BeginWrite(bData, 0, bData.Length, new AsyncCallback(EndSend), null);" i don't get the error and the program keeps working just fine.
When I remove this/all breakpoint/s the program flushes.....
Avatar
Alex #2
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

what do you mean by the program flushes?

The exception "Unable to write data to the transport connection: Cannot access a disposed object." looks like the socket is closed/disposed for some reason when you try to send data on the connection. Is the socket still connected when you get this exception or is the socket closed?
Can can write a test case to reproduce this behaviour?

Alex
Avatar
Rotjoeng #3
Member since Jul 2006 · 14 posts
Group memberships: Members
Show profile · Link to this post
hi,
flushes = crashes

I've checked if the socket is connected or not. It says it isn't connected anymore, so i've placed a check before "m_NetworkStream.BeginWrite(bData, 0, bData.Length, new AsyncCallback(EndSend), null);", where i connect the socket if it's not connected. It still doesn't work.

I can't reproduce a test case, it's not in the miniclient.

Could it be that the problem lies in the speed it works. We're working on a fast network and fast computers here.

Filip
Avatar
Alex #4
Member since Feb 2003 · 4447 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by Rotjoeng:
I've checked if the socket is connected or not. It says it isn't connected anymore, so i've placed a check before "m_NetworkStream.BeginWrite(bData, 0, bData.Length, new AsyncCallback(EndSend), null);", where i connect the socket if it's not connected. It still doesn't work.

I can't reproduce a test case, it's not in the miniclient.
You have to debug this and find out why the socket gets a disconnect. I assume you have a unhandled exception in your program which causes a disconnect in agsXMPP. If you don't catch exceptions they will be forwarded to the surrounding code which is at the end always in agsXMPP.

Quote by Rotjoeng:
Could it be that the problem lies in the speed it works. We're working on a fast network and fast computers here.
i would say No, agsXMPP is optimized for high speed, and used from many clients in server implementations with very high load.

Alex
Avatar
Rotjoeng #5
Member since Jul 2006 · 14 posts
Group memberships: Members
Show profile · Link to this post
thx,

i will try that.
Avatar
yeawsing #6
Member since Jul 2006 · 33 posts · Location: South Korea
Group memberships: Members
Show profile · Link to this post
Hi, RotJoeng

I have similar problem like your
Unable to write data to the transport connection: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'..

In my code I have a logout function

  1.         public void logout()
  2.         {
  3.             if (XmppCon != null && XmppCon.Authenticated)
  4.             {
  5.                 XmppCon.Close();
  6.             }
  7.             //XmppCon.SendMyPresence();
  8.             this.Close();
  9.         }

At first, I thought when logout I should send my current presence but this wrong.  Since the connection already close, and I send my presence.  The program will throw an exception like the message above.  So I guess u should check in your program when the connection is closing.
I am still learning..., hope I can contribute back.
YS
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS