B4J Question How do I destroy a socket? I need "gsocket" below destroyed after close.

RickV

Member
Licensed User
Hi all, I have a real curly one and very new to b4j.

I have a server app, it listens, accepts a request into a client class using the code below
Main
brj:
private Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Not(Successful) Then Return
    Dim connection As Client
    connection.Initialize(NewSocket)

Client code
b4j:
Public Sub Initialize(socket As Socket)
    gsocket = socket
    AStreams.Initialize(gsocket.InputStream, gsocket.OutputStream, "AStreams")

THis work great, I connect, exchange data blh blah and disconnect. The client is detroyed BUT gsocket will not get destroyed and any subsequent connections come back to this same socket as far as I can tyell, nocevent triggered in Main to create a new instance of the client etc.

How do I destroy gsocket and force the server part to create a whole new instance. I have read stuff on severinpl etc and know there are things that can be set ;ike solinger false with timeout=0 byt U cannot access them.
 

OliverA

Expert
Licensed User
Longtime User
All you have to do is close the socket. Actual object destruction will be taken care of by the garbage collector (as it relates to B4J). I'm attaching a test socket client and server application (the client is a mod of the Network Example and the server is a mod of the FTP Server). On the server, every client connection creates a new socket (indicated by the increase of the first number in the ###:### pair, with the socket# taken displayed as the second number).

 

Attachments

  • TestSockClient.zip
    4.5 KB · Views: 94
  • TestSockServer.zip
    6.1 KB · Views: 93
Upvote 0

RickV

Member
Licensed User
Thanks, I will take a look at them ☺
I know the collection should get rid of it but it doesnt. A subsequent connection occurs but no data is received or sent.
I will read the code attached and come to a conclusion and come backThanks again ☺
 
Upvote 0

RickV

Member
Licensed User
Thank you so much. That works like it is supposed to. Any ideas why the other code could not let the socket get destroyed ?
 
Upvote 0

RickV

Member
Licensed User
I am using the server one, added another layout and generated the globals b4xMainPage. How do I set the views properties from withing TestCient ?

B4XMainPage
Private CD As B4XView
Private ClientList As B4XView
Private Label10 As B4XView

TestClient
sub astreams newdata....
Label10.Text = received datastram or part of.........
 
Upvote 0
Top