Client not disconnect from server over socket ?

pikthai2004

Member
Licensed User
Longtime User
Hi everyone,

Help me please.

I try to disconnect from client side (android device) but it not.

This is code for client side

Sub btClose_Click
Log("Client Close")
AStreams.Close
Socket1.Close
End Sub

But Server side ( on PC ) still connected.

Thank you very much.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is in your server code. It doesn't recognize the state change.

Both the visual designer and B4A-Bridge use sockets to communicate. In these implementations the server sends a "ping" every second and listens for a "ping" response. If no ping message arrives after 10 seconds the connection is closed on both sides.
 
Upvote 0

tmV23

Member
Licensed User
Longtime User
Hello,

I've tested the timeouts on my server and after using "Socket1.Close" the b4a app still will respond and keep the connection alive.

Only after closing the b4a app will the server kill the connection.

Why is that?

Is this a bug in the b4a software, that won't allow Socket1.Close to actually do something other then disable any more connects?

I've searched the forum for this answer a lot. Is it possible to get a really good explanation for why Socket1.Close does not work.

Better yet can it be fixed so Socket1.Close will work the same as if the app is closed?

Previous answers were to use android as the server instead. I just don't see how that helps answer this question.

Also I've tested the Winsock.close in vb. My server Will kill the connection and allow reconnect. So it's just the b4a app not working.

Thank you :)
b4a is the best !!
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Hello,

I've tested the timeouts on my server and after using "Socket1.Close" the b4a app still will respond and keep the connection alive.

Only after closing the b4a app will the server kill the connection.

Why is that?

Is this a bug in the b4a software, that won't allow Socket1.Close to actually do something other then disable any more connects?

I've searched the forum for this answer a lot. Is it possible to get a really good explanation for why Socket1.Close does not work.

Better yet can it be fixed so Socket1.Close will work the same as if the app is closed?

Previous answers were to use android as the server instead. I just don't see how that helps answer this question.

Also I've tested the Winsock.close in vb. My server Will kill the connection and allow reconnect. So it's just the b4a app not working.

Thank you :)
b4a is the best !!
I don't know if this helps, I am closing the socket upon activity_pause, while just before, when my process is done, I'm sending a notification to the server to also close its socket. From my testing, I see that server socket is closed when this command is executed. But I'm talking about androids both as a server and client.
 
Upvote 0

tmV23

Member
Licensed User
Longtime User
Thank you mc73. It does help. I will start looking for a way to kill the connection on the server somehow as a work around for now. That's a good idea!

It sure would be great to find out why close doesn't actually close though.

Thanks again

If anyone else can explain what's happening that would be great to.
 
Upvote 0

jgbozza

Member
Licensed User
Longtime User
What if the client is a handheld and someone walks away with it, losing the connection with the router?
When it comes back the server side is still opened and you'll have to establish a new connection opening an unnecessary socket that could crash your application depends on how you're handling the incomming data
 
Upvote 0
Top