Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Go Back  Xtreme Visual Basic Talk > > > Socket event = to dataarrival in vb.net


Reply
 
Thread Tools Display Modes
  #1  
Old 12-21-2012, 10:03 AM
skip0464's Avatar
skip0464 skip0464 is offline
Centurion
 
Join Date: Dec 2003
Location: New Jersey
Posts: 105
Question Socket event = to dataarrival in vb.net


I am using vb.net (visual studio 2008) I can write a client application that connects to a tcp server, then when data is delivered from the server i can press a button and receive the data on the client side.

I want to this action to be event driven. When data arrives kick of a routine.

In vb (6.0) the winsock active x had an event called dataarrival and it did that, is there a way to do that in vb.net?
Reply With Quote
  #2  
Old 12-23-2012, 01:51 AM
PeetSoft's Avatar
PeetSoft PeetSoft is offline
Centurion
 
Join Date: Jun 2003
Location: HHW - the Netherlands
Posts: 184
Default

Quote:
Originally Posted by skip0464 View Post
I am using vb.net (visual studio 2008) I can write a client application that connects to a tcp server, then when data is delivered from the server i can press a button and receive the data on the client side.

I want to this action to be event driven. When data arrives kick of a routine.

In vb (6.0) the winsock active x had an event called dataarrival and it did that, is there a way to do that in vb.net?
Code:
serialport.datareceived
__________________
-----------------------------------------------------
If debugging is the art of removing bugs, then
programming must be the art of inserting them.
I do comply with Flyguy's signature (If he still had one)
Reply With Quote
  #3  
Old 12-23-2012, 08:18 AM
AtmaWeapon's Avatar
AtmaWeaponSocket event = to dataarrival in vb.net AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Except the question is about sockets, not serial ports.

I don't fiddle with sockets very often; I tend to prefer the TCPListener and other classes like it. But it looks like what you do if you want a socket to wait for data in a non-blocking manner is call Listen(), then occasionally Poll() with a SelectMode.SelectRead argument.

There are no events because the class is a pretty faithful implementation of the Berkley Sockets API that's been around forever, and C didn't have events.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 12-23-2012, 10:28 PM
passel's Avatar
passelSocket event = to dataarrival in vb.net passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

What are you doing when you press the button?
Assuming you are doing what is needed to do the read, what I usually do is just start a background thread with the blocked read, inside a loop. That way, when ever data comes in, the read returns, I process it, then loop back up and do another read.
Being in a background thread won't hang up the rest of the code, and I find it a bit simpler than setting up a callback function.
One caveat, possibly, compared to what you're doing is that if you're updating any GUI components based on the received data, you can't update them from the background thread. So, you would have to use cross-threading techniques to get the data back to the GUI thread, such as using Invoke, or one of the System.Collections.Concurrent classes, such as ConcurrentQueue, which provides a queue that can be used between threads.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 12-24-2012, 09:32 AM
skip0464's Avatar
skip0464 skip0464 is offline
Centurion
 
Join Date: Dec 2003
Location: New Jersey
Posts: 105
Default

Passe, I moved forward with a solution that is almost identical to your suggestion. However AtmaWeapons solution now poses some questions for me. The TCPListener I just always assumed that was a server side class. Not that I read that anywhere it was just an assumption on my part. Now I guess i would run the listener in a background thread or is it not necessary.

My receiving routines update a sql server table with receieved info, it has no effect on active interfaces.

Thank you both for responding and helping with my applications, being a solo it guy in a company does present learning challenges. so thanks again.
Reply With Quote
  #6  
Old 12-24-2012, 08:27 PM
passel's Avatar
passelSocket event = to dataarrival in vb.net passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Putting TCPListener in a Background thread would be my preference.
I currently have a process that sits in the middle between three other processes which controls and passes data between them. I communicate with Bi-directional TCP (using TCPClient) with one process. That client connection is done in a background thread, actually inside a doubly nested loop. The inner loop does the reading and writing once the connection is established. The outer loop only comes into play if the connection can't be made, or is lost. The outer loop will continue to try connecting to the server periodically. Once the connection is made, then the inner loop does the blocking reads.
The process also a TCP server (TCPListener) for another process, so that waiting for connection and processing reads is another background thread. Then there is a UDP connection with another process, so the blocking read for that connectoin is in another background thread.
Blocking reads in background threads just seems the clearest approach for me. I did experiment with the lower level socket interface and callback when I first started looking at socket interfaces in .Net, and they work fine, but I've pretty much settled on using the UDPClient and TCPClient classes and background threads to do the job and it has worked fine for me so far.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
 
Socket event = to dataarrival in vb.net
Socket event = to dataarrival in vb.net
 
-->