wrote a small program to communicate with a android tablet. The program consist of label,textarea and buttons,serversocket. The tablet has a small porgram written in B4A which send a code over wifi to the ethernet connected pc where the gambas program runs.
I have a connection as gambas sees the ip addres and the selected port which is shown in the textarea. Connect to : <ipaddres> port:<port where serversocket listens>
The progam is inspired from the blog Capain Bodgit,( thanks mr SteveDee)
I have the connection and port listening though i cannot read the message send from the tablet( confirmed by the B4A packet send). the message consist of a single coordinate like "01" . In a terminal tcdpdump is see a packet with lenght 6.
In the gambas program when i look at the length of the strmsg from the Socket_read() sub from mysocket it is also 6 but i don't find a way to show it here in message.
The tables send the message string as bytes i suppose. Do i have a data conversion problem or has it a diffrent cause.
Thanks for your help.
Gambas class file
Code: Select all
' Gambas class file Public Sub Form_Open() ServerSocket1.port = 12345 ServerSocket1.type = Net.Internet End Public Sub Form_Close() If ServerSocket1.Status Then ServerSocket1.Close Endif End Public Sub btlisten_Click() ServerSocket1.Listen(1) If ServerSocket1.status = Net.active Then btlisten.Enabled = False lbIpstatus.text = "Connected - Listen to port: " & ServerSocket1.Port Endif End Public Sub btQuit_Click() If ServerSocket1.Status Then ServerSocket1.close Endif Quit End Public Sub btverbose_Click() Dim shellvar As String taInfo.text = gb.crlf & ServerSocket1.status & gb.crlf & "------------------------------------------------------------------" & gb.CrLf Shell "netstat -at | grep 'LISTEN'" To shellvar taInfo.text &= shellvar End Public Sub ServerSocket1_Connection(RemoteHostIP As String) Dim strmsg As String Dim mysocket As Socket If ServerSocket1.Status > Net.Inactive Then mysocket = ServerSocket1.Accept() mysocket.Blocking = False If mysocket.Status = Net.Connected Then taInfo.text &= gb.crlf & "Connected: " & mysocket.RemoteHost & " Port:" & mysocket.RemotePort & gb.CrLf Else taInfo.text &= gb.crlf & "SocketStatus: " & mysocket.Status & " not Net.connected " & gb.CrLf Endif Endif End Public Sub Socket_read() Dim strMsg As String Dim convmsg As String If Last.status <> Net.Connected Then taInfo.Text &= "no incoming message." Return Else Read #Last, strMsg, Lof(Last) If strmsg = "" Then strmsg = "empty" Endif Message("Lenght: " & String.Len(strmsg) & gb.CRLF & " strmsg: " & Str$(strmsg)) Endif End Public Sub Socket_closed() taInfo.text &= gb.crlf & "Connection with socket closed" End Public Sub ServerSocket1_Error() Message.Error("Unable to bind socket") End Public Sub btCloseServer_Click() If ServerSocket1.Status Then ServerSocket1.Close btlisten.Enabled = True lbIpstatus.text = "Port closed - Disconnected" Endif End