I'm trying to do a two ways communication between a PC running .NET Client-Server and an Android device, (the code is made with Basic4Android). Sending from Android to PC works fine, the problem occours when i try to send from the PC to Android. I'm trying to use the ServerSocket but when the PC tries to connect to the Android the device, time-out is reached and an exception is raised. The code i'm using is the following:
PC .NET
Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
sock.Connect(remoteip, 8565)
Dim buffer() As Byte = UTF8.GetBytes(string)
sock.Send(buffer)
sock.Close()
and the Android code:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim ss As ServerSocket
Dim IS1 As InputStream
Dim timerListener As Timer
End Sub
Sub Activity_Create(FirstTime As Boolean)
timerListener.Initialize(timerListener, 1)
ss.Initialize(8565, "ss")
ss.Listen
End Sub
Sub ss_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
IS1 = NewSocket.InputStream
timerListener.Enabled = True
Else
ToastMessageShow("Error.", True)
End If
End Sub
Sub timerListener_Tick
Dim cv As ByteConverter
If IS1.BytesAvailable > 0 Then
Dim buffer() As Byte
IS1.ReadBytes(buffer, 0, IS1.BytesAvailable)
Dim result As String = cv.StringFromBytes(buffer, "UTF8")
ToastMessageShow(result, True)
timerListener.Enabled = False
End If
End Sub
What can be the issue? Thank you in advance!!