Problem with socket / astreams

LittleBritaly

Member
Licensed User
Longtime User
I've a desktop app written in Pascal/Lazarus running on a windows 7 machine with no firewall running, this program is in development and will be deployed to a windows xp system.

I've also an app written in basic4android (I've only used this for a couple of days) that communicates with the desktop app over tcp/ip.

In lazarus I am using lnet components, both programs can be either a client or server, but I really need the desktop app to be the server (multiple Android phones eventually need to connect to this).

B4a starts its server like this

If FirstTime Then
Server.Initialize(5000, "Server")
Server.Listen
.......................

Upon connection, this sub handles it (not my own code, copied from a demo)

----------------
Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
If Successful Then
ToastMessageShow("Connected", False)
Socket1 = NewSocket
AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
Else
ToastMessageShow(LastException.Message, True)
End If
Server.Listen
End Sub
------------------

This works great, the desktop app connects with the android device in milliseconds, BUT !!, when trying to connect from the Android device to the desktop app (which is in server mode), this takes about TWENTY seconds.

Here's the code i use to connect to the desktop app (I've used different timeouts when trying to connect, nothing appears to work). :-

Sub Btn_Connect_Click
Vibrate.Vibrate (50)
Socket1.Initialize("Socket1")

Socket1.Connect("192.168.2.101",5000,1000)

ToastMessageShow("Tyring to connect....", False)
End Sub

Any ideas anyone (going to check lazarus code)?, anyone had similar issues ?
 
Last edited:

LittleBritaly

Member
Licensed User
Longtime User
I've tried on two different wireless networks with two different android phones, but using the same desktop machine, same result each time (slow to connect to Windows server, instant from windows client to Android server).

I'm going to introduce a fresh laptop into the equation and see if windows client to windows server suffers the same result.

Is there any way to see log files on the android device during connection ?, eg on a linux box I could run "tail -f /var/log/whatever" to see what was happening, any such thing available for B4a ?


Thanks.
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
I have done some experimenting with sockets between B4A and .NET code on local PC's as well as server (in both directions) and have not encountered any issues myself either.

I would guess:
- or: some network/routing issue
- or: the server app is buffering the done and this data gets flushed only after 20 seconds or so (only if it is not really the connection that takes so much time, but the sending of data)
 
Upvote 0
Top