-
Dec 7th, 2012, 08:12 AM
#1
Thread Starter
Addicted Member
Help using easysockets?
http://www.vbforums.com/showthread.p...t=#post3852009
I'm just starting out with tcp on vb.net (2010 exp) and I'm having a heck of a time understanding how it all works. I sure do miss WinSock on VB6
ANyway, I found the above class and it looks promising but I can't figure out how to use it. Actually, I can't seem to get past declaring it (ugh, newbs!)
I tried
private withevents myConnection as easysocket = new easysocket
<later>
myConnection.Address = myTCPAddress.tostring
myConnection.Port = str(myPort)
myConnection.Connect
I just get object not set...
If anyone has experience with this I'd love to see a little sample!
Thanks
-
Dec 7th, 2012, 08:24 AM
#2
Thread Starter
Addicted Member
Re: Help using easysockets?
Oh, I should mention. I think the object might be the sub for the OnConnectionEstablished event - I looked through the class and didn't see where I could pass the sub address to the class so I just made a sub :
ConnectionEstablished(ea As easySocket.DataReadEventArgs)
It was a wild guess and probably wrong 8(
-
Dec 7th, 2012, 09:58 AM
#3
Thread Starter
Addicted Member
Re: Help using easysockets?
Ok, while driving it dawned on me that the class is raising an event in exactly the same way as a forms control (which is a class). I changed my subs to something like this (cant remember the exact names)
private sub DataReceiver(sender as Object, e as System.EventArgs) handles MyConnection.DataReceived
That hasn't solved the error I get as soon as I click the connect button. It actually says object not set to an instance of an object but doesn't indicate where in the code this is happening. I'm assuming since the only thing I changed in my existing code is the myConnection parts it's something in the newly created myConnection object...
-
Dec 7th, 2012, 02:32 PM
#4
Thread Starter
Addicted Member
Re: Help using easysockets?
Well no surpise - it was me. I was supplying myTCPAddress.tostring but I'd cut out the myTCPAddress declaration when I removed my old tcpclient code. Odd that the debugger didn't home in on the offending assignment.
Still have one problem which I'm pretty sure isn't me (exactly). I'm trying to disconnect and using myConnection.close() (which is TCPClient.close()) but the easysocket EndARRead method throws an exception when it tries an EndRead() after the close. I'm assuming either it's not supposed to do that last endread or .Close() is the wrong way to disconnect. I can't find anything else to use to disconnect from the server though.
Any thoughts?
-
Jan 2nd, 2013, 03:34 PM
#5
Re: Help using easysockets?
It shouldn't be calling EndRead after the close, but it may not matter, either. Any activity with a network connection should be performed in a Try...Catch block, because exceptional circumstances will happen. You may have already figured out a solution to this, or you may have wandered off. In any case, I have found that there are some exceptions related to network issues that are worth just swallowing without making the effort to fix them. This doesn't seem to be such a case, though, since it appears to be clearly a case of code being out of order.
My usual boring signature: Nothing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|