Send message to TCP device

  • Thread starter Thread starter Matt
  • Start date Start date
M

Matt

We have an Intermec stationary computers setup to basically clock people in
and out... I have code running (borrowed from Planet Source Code and
modified to suit) to receive packets from these computers each time someone
swipes their card. The code sends back a response to the device with
basically a clocked in/out successful/unsucessful message. This works good,
but the code will only send a message to the device if it receives a stream
from it first. I need to be able to send a message to the device,
un-prompted. Here is an example of the working code... on the line
identified is where the code stops and waits for a stream from the device..
I need to bypass this wait section and go right to the 'Stream.write' line..
but since the stream is dependent on the Tcpclient... which is waiting for a
message... :o)

\\
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim bytes(1024) As [Byte]
Dim data As [String] = Nothing
Dim stream As Sockets.NetworkStream
Dim Clock As New
Sockets.TcpListener(Dns.GetHostByName("10.100.4.29").AddressList(0), 33)
Dim client As Sockets.TcpClient
Dim msg As Byte()

Clock.Start()

client = Clock.AcceptTcpClient ' <--- Program stops here to
listen for a stream from 'Clock'

stream = client.GetStream()
msg = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text)
stream.Write(msg, 0, msg.Length)
Clock.Stop()
End Sub
//

Thanks!

Matt
 
I think you could set up a TcpClient on another thread and connect to the
device, and then send it a message. Of course, the device would have to be
listening for it.
-Brian
 
Back
Top