473,395 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

event of receive data on net work

91
Since TCPClient in VB2005 does not implement data_received event like Winsock, how can I program an event routine to handle data_received event? Thanks.
Jun 10 '08 #1
7 1012
Plater
7,872 Expert 4TB
Setup a thread to check to see if data is received?
Jun 10 '08 #2
qfchen
91
So inside the thread, using Do-Loop to check sock.available? any sample code? thanks
Jun 10 '08 #3
Plater
7,872 Expert 4TB
Well you would want to have thread.sleep()s so you don't eat up the cpu time. But basically yes.
You can even tell it to fire an event if you want.
Jun 10 '08 #4
qfchen
91
Here is the piece of code which is running inside thread, not sure where to put thread.sleep(), how can it save CPU time. Thanks
Public Sub start()
Dim stream As NetworkStream
Dim st As Boolean

Dim cmd, parm As String
Dim len, index As Integer
Dim s As String = Nothing

stream = Client.GetStream()
Do
st = stream.DataAvailable

If (st = True) Then
Dim bytes(Client.ReceiveBufferSize) As Byte
stream.Read(bytes, 0, CInt(Client.ReceiveBufferSize))
s = Encoding.ASCII.GetString(bytes)
len = s.Length
index = s.IndexOf(":")
If index < 0 Then
Exit Sub
End If

'example CARD:1234567$
cmd = s.Remove(index, len - index) 'keep CARD as cmd
parm = s.Remove(0, index + 1) 'remove CARD:
index = parm.IndexOf("$")
Try
parm = parm.Remove(index, parm.Length - index)
Catch ex As Exception
End Try
stn.ProcRXCmd(cmd, parm)
End If
Loop
End Sub
Jun 10 '08 #5
qfchen
91
I think that I had figured out, just put the sleep() in side the Do-Loop. It works

In my application, I use TCPClient to connect to multiple device, each device will have one thread running in my application to handle all activities asociate with that device, each device will send information to my application. My question is: If the info from all device come at the same time, will any data or string be lost, does TCPIP protocol take care and guarantee the traffic? Any setting needed for network to optimize the traffic?

Thanks
Jun 11 '08 #6
Plater
7,872 Expert 4TB
I believe TCP should make sure you don't lose any data.
Jun 11 '08 #7
qfchen
91
normally, in which situation, the network connection may lose? I notice the loss connection always happened during data transmission or after transmission. it must something happened during transmission. Any idea? Thanks.
Jun 11 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: User | last post by:
Hi, How better is to implement my own event (and calling my raiseevent) instead of calling a function. I receive a lot of data via winsock control, should I raise my event when receiving all...
8
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that...
21
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
2
by: Craig | last post by:
Hi I listen on a port, when data is received I raise an event (OnMessageReceived) in the while loop as follows: private void WaitForConnection() { TcpListener listener = new...
4
by: Charles Law | last post by:
Suppose a worker thread needs to signal to the main thread that an event has occurred. Ordinarily, any event raised by the worker thread will be on its own thread. How can the worker thread...
2
by: Kjell Kristiansson | last post by:
I have not been able to figure out how to catch the click event from a button that is added dynamically to a table. In priciple the process is as follows: When I first create the page I analyse...
3
by: Robert W. | last post by:
I'm new to ASP.net programming so excuse my ignorance if the following question seems overly simplistic. I've created a simple Login form with 3 primary WebControls: - A TextBox for the Username...
22
by: Oriane | last post by:
Hi there, I have to write an algorithm in .NET/C# which perform some task but has to be stopped after an intreval of dT seconds. Something like: dT = 30sec; for (;;) { t0 = GetCurrentTime...
19
by: zacks | last post by:
I have a .NET 2.0 MDI application where the child form has a Tab Control. Each of the Tab in the Tab Control has a Validating event to handle what it should do when the user changes tabs. But...
2
by: OBones | last post by:
Hi all, I'm currently trying to receive replies to a UDP broadcast that I sent and I can't get it to work. I know the datagrams are sent as I see them with WireShark, but my C# code does not see...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.