outcast1881
Active member
- Joined
- Aug 25, 2006
- Messages
- 38
- Programming Experience
- Beginner
Hi everyone,
I am writing a client-server connection.The server is an rfid device.When I enter a query from textbox1,I get the respond in textbox2(the tag numbers).And when the conditions change for instance new tags come into the environment the query remains the same but how to change the respond automatically according to new data.Indeed the rfid reader continuously reads and saves the new data but how to get it in my textbox2....
sorry,I coulnd't express myself clearly,I hope someone had understood what I tried to explain and can help me as well.
Kindest regards,
Can
I am writing a client-server connection.The server is an rfid device.When I enter a query from textbox1,I get the respond in textbox2(the tag numbers).And when the conditions change for instance new tags come into the environment the query remains the same but how to change the respond automatically according to new data.Indeed the rfid reader continuously reads and saves the new data but how to get it in my textbox2....
sorry,I coulnd't express myself clearly,I hope someone had understood what I tried to explain and can help me as well.
Kindest regards,
Can
VB.NET:
Imports System.NET.Sockets
Imports System.Text
PublicClass Form1
Dim tagid AsString
Dim tcpClient AsNew System.Net.Sockets.TcpClient
Dim networkStream As NetworkStream
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
tcpClient.Connect("111.11.11.111", 8080)
networkStream = tcpClient.GetStream()
MessageBox.Show("connected")
EndSub
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If networkStream.CanWrite And networkStream.CanRead Then
Dim sendBytes(TextBox1.Text.Length) AsByte
'Convert the contents of textbox1 to bytes for transmission(here I enter the query in the form)
sendBytes = Encoding.ASCII.GetBytes(TextBox1.Text)
'send the contents of textbox1 to address specified by networkstream (here I get the respond from the device)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes(tcpClient.ReceiveBufferSize) AsByte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Output the data received from the host to the textbox.
Dim returndata AsString = Encoding.ASCII.GetString(bytes)
TextBox2.Text = returndata
'attaining textbox value(query result) to tagid variable
tagid = TextBox2.Text.Substring(18, 6)
Else
IfNot networkStream.CanRead Then
Console.WriteLine("cannot not write data to this stream")
tcpClient.Close()
Else
IfNot networkStream.CanWrite Then
Console.WriteLine("cannot read data from this stream")
tcpClient.Close()
EndIf
EndIf
EndIf
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'a unique code used to quit the server
Dim sendBytes("!quit!".Length + 1) AsByte
'Convert the word !quit! to Bytes
sendBytes = Encoding.ASCII.GetBytes("!quit!")
'send the quit command to the server
networkStream.Write(sendBytes, 0, sendBytes.Length)
'close the connections
networkStream.Close()
tcpClient.Close()
'exit the program
Application.Exit()
EndSub
EndClass
Last edited by a moderator: