System.ArgumentException

Drstein99

Junior Contributor
Joined
Sep 26, 2003
Messages
283
Location
Audubon, Nj
I have my own class, that stores a tcpclient object, mainly handles communcations for each connection.

Now it works fine connecting two computers, but when i connect three it goes haphazzard with "System.IO.IOException:"


I use the following command:

myTcpclient.GetStream.BeginRead(MYreadBuffer, 0, READ_BUFFER_SIZE, AddressOf myStreamReceiverSub, Nothing)

And during the endread call, it throws the error:

Unable to read data from the transport connection. ---> System.ArgumentException: The IAsyncResult object was not returned from the corresponding asynchronous method on this class.
at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)

---

I dont understand what this is or how to fix it can someone help please?
 
I don't know if this has anything to do with it, but BeginRead returns an IAsynchObject, which you're supposed pass in as an argument when you call EndRead so my question is,
1) Are you calling EndRead
and if so, are you passing in the IAsynch object that was returned by ther BeginRead method,
 
this is copied from the streamreciever function i am using:

Private Sub StreamReceiver(ByVal ar As IAsyncResult)

If Me.client.GetStream.CanRead Then
SyncLock Me.client.GetStream

BytesRead = Me.client.GetStream.EndRead(ar)
end synclock
endif

-
does it look right?
 
ALSO, WHEN my STREAMRECEIVER event is called, I am calling:

BytesRead = Me.client.GetStream.EndRead(ar)

---

Sometimes it returns 0 byes, but i can see that there is a string populated, with data in there. What would cause that to happen? Will this event stack and run on top of each other if it gets more then one packet by before its done processing the function?
 
Back
Top