I am having problems trying to use my android (Basic4Android) to communicate with my PC running a .net TCP server. I need to be able to have buttons that send 4byte commands to the server and receive back a response. When I run the program on the android the server does connect and receives the string "INFO", but then nothing else sends or receives until I restart the program and it only sends the command "INFO" again. I don't get any errors when I press the buttons to send commands, but the server never receives anything. The server is a Windows form multi-thread program written in VB.NET. I wrote a VB.NET client program that works that I can attach as an example of what I am trying to do. This is my first attempt at a Android application and so far I am just modifing the network examples I found in the tutorials.
The code is below... Thanks
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("#.#.#.#" , 8000, 20000) 'My IP address goes here
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