TCP Android client to Windows PC server

khos

Member
Licensed User
Longtime User
Hi everyone,

I would like to ask for help or pointers on how I could achieve the following, how can I get TCP communications from an Android client to a Windows PC server (written in VB2010)?

I want to be able to send text just in the one way communication via tcp (or udp?).
I have looked at several tutorials / posts e.g. AsyncStreams Tutorial but so far I cannot see what kind of code I need to use on the Windows PC side, has anyone out there got a sample of this available for me to look at / understand?

I want to use the http://www.b4x.com/forum/basic4andr.../7669-asyncstreams-tutorial-3.html#post121661 TestClientSocket.zip on the B4a side..that part seems ok...but what kind of code would I need to use on the Windows PC side?

Would something like this be fine to use (using VB for Visual Studio 2010):
Dim serverSocket As New TcpListener(20001)
Dim requestCount As Integer
Dim clientSocket As TcpClient
serverSocket.Start()
clientSocket = serverSocket.AcceptTcpClient()
requestCount = 0
While (True)
Try
requestCount = requestCount + 1
Dim networkStream As NetworkStream = clientSocket.GetStream()
Dim bytesFrom(10024) As Byte
networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
Dim dataFromClient As String = System.Text.Encoding.UTF8.GetString(bytesFrom)
dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
TextBox2.Text = dataFromClient
End Try
End While

Thanks,
Kim
 

flyingbag

Member
Licensed User
Longtime User
Hello,
You can easily search for "VB.Net Server Socket Example" on google and get something like this
There should be many examples to choose from...

Problem with running it on windows is most of the times the inbuilt firewall will not allow the client to connect ...

flyingbag
 
Upvote 0

khos

Member
Licensed User
Longtime User
Thanks everyone for your help, I'll get a new post done for the issue I have, got some debug screen which might help.
 
Upvote 0
Top