I have a need to have a vb.net form TCP (or UDP) server running that will accept 4-byte commands from my android and send a response string back to the android. I already have a workable vb.net forms server running on a PC and a vb.net client program working o.k. together. I am trying to get the android client working and it does connect to the server and sends one command (I have it send "INFO" when the program starts, which the server does see). I try sending other 3-byte commands when buttons are pressed, but nothing happens. I probabbly should have started with UDP instead of TCP, but I couldn't find any examples anywhere that helped.
* note the 127.0.0.1 address is replaced with my actual server when I run the program
* I can leave a copy of my vb.net client code I am trying to duplicate on the Android if that would be helpful?
* Input stream is commented out until I figure out why the send command isn't working correctly.
My Android code:
Sub Process_Globals
Dim Socket1 As Socket
End Sub
Sub Globals
Dim Button_ARM As Button
Dim Button_STAY As Button
Dim Button_AUTO As Button
Dim Button_OFF As Button
Dim Label_Received As Label
Dim Label_Sent As Label
'Dim tr As TextReader
Dim tw As TextWriter
'Dim sb As StringBuilder
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Alarm_Control")
Socket1.Initialize("Socket1")
Socket1.Connect("127.0.0.1" , 8000, 20000)
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful = False Then
Msgbox(LastException.Message, "Error connecting")
Return
End If
'tr.Initialize(Socket1.InputStream)
tw.Initialize(Socket1.OutputStream)
tw.WriteLine("INFO")
Label_Sent.Text = "Sent INFO"
tw.Flush
'sb.Initialize
'sb.Append(tr.ReadLine)
'Label_Received.Text = sb.ToString
'Socket1.Close
End Sub
Sub Button_ARM_Click
tw.WriteLine("O001")
tw.Flush
Label_Sent.Text = "Sent O001"
End Sub
Sub Button_STAY_Click
tw.WriteLine("O002")
tw.Flush
Label_Sent.Text = "Sent O002"
End Sub
Sub Button_OFF_Click
tw.WriteLine("O000")
tw.Flush
Label_Sent.Text = "Sent O000"
End Sub
Sub Button_AUTO_Click
tw.WriteLine("O003")
tw.Flush
Label_Sent.Text = "Sent O003"
End Sub
* note the 127.0.0.1 address is replaced with my actual server when I run the program
* I can leave a copy of my vb.net client code I am trying to duplicate on the Android if that would be helpful?
* Input stream is commented out until I figure out why the send command isn't working correctly.
My Android code:
Sub Process_Globals
Dim Socket1 As Socket
End Sub
Sub Globals
Dim Button_ARM As Button
Dim Button_STAY As Button
Dim Button_AUTO As Button
Dim Button_OFF As Button
Dim Label_Received As Label
Dim Label_Sent As Label
'Dim tr As TextReader
Dim tw As TextWriter
'Dim sb As StringBuilder
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Alarm_Control")
Socket1.Initialize("Socket1")
Socket1.Connect("127.0.0.1" , 8000, 20000)
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful = False Then
Msgbox(LastException.Message, "Error connecting")
Return
End If
'tr.Initialize(Socket1.InputStream)
tw.Initialize(Socket1.OutputStream)
tw.WriteLine("INFO")
Label_Sent.Text = "Sent INFO"
tw.Flush
'sb.Initialize
'sb.Append(tr.ReadLine)
'Label_Received.Text = sb.ToString
'Socket1.Close
End Sub
Sub Button_ARM_Click
tw.WriteLine("O001")
tw.Flush
Label_Sent.Text = "Sent O001"
End Sub
Sub Button_STAY_Click
tw.WriteLine("O002")
tw.Flush
Label_Sent.Text = "Sent O002"
End Sub
Sub Button_OFF_Click
tw.WriteLine("O000")
tw.Flush
Label_Sent.Text = "Sent O000"
End Sub
Sub Button_AUTO_Click
tw.WriteLine("O003")
tw.Flush
Label_Sent.Text = "Sent O003"
End Sub