Socket Connection

Rusty

Well-Known Member
Licensed User
Longtime User
I have opened a socket with NO server listening (as a test) and I still get a successful socket connection.
B4X:
If Main.TCP.IPaddress <> "" Then    'we have defined a server, but it is not online
            Socket1.Close
            XferFile.Initialize
            Socket1.Initialize("Socket1")
            SetBufferSize(Socket1, ChunkSize)
            Socket1.Connect(Main.TCp.IPAddress, Main.TCP.Port, 0)
        End If
B4X:
Sub Socket1_Connected (Successful As Boolean)
    If Successful = True Then
Log("Socket connected")
        Main.TCP.Connected = -1                        'tell the app we have a TCP server available
        MsgAcked = True
        WeAreConnected = True
'        N.SetInfo("Network", "TCP Connected! ", Main)    'let them know it is connected
        Astreams.Initialize(Socket1.InputStream,  Socket1.OutputStream, "AStreams")
        SendMsg(chnCommands,"MYID:~" & Main.version.SerialNo & "~" & Main.LicenseData.GroupCode & "~Version: " & Main.Version.NewVersion & "~" & _
                Main.CS.FacilityID & " " & Main.licensedata.Addr1 & " " & Main.LicenseData.City & ", " & Main.LicenseData.state)    'let them know who we are
    End If
End Sub
I receive the Log message socket connected even when nothing is listening.
How can i be getting a SUCCESS when there is nothing on the other end listening?
Thanks,
 

Rusty

Well-Known Member
Licensed User
Longtime User
How would the OS open the port?
The application starts, issues a StartService(TCPService); there is no listener anywhere (I've shut down the entire network) and the socket1.connected shows a successful connection.
Any ideas or suggestions?
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
My client has two different TCP configurations installed.
1. The port address is 7890
2. The port address is 443

I recall seeing that ports under 2000 (or so) are reserved or could be a problem. If I am using 443, will this necessarily be a problem?
Thanks
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Is there any way to force the OS to close the port(s) or to detect that this is an OS port as opposed to one I open?
Thanks,
Rusty
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
As I've said in another thread, I am using arrays of sockets and streams, for two reasons: One, It's necessary for my app (many clients involved) and secondly, occasionally I'm facing some troubles with connections. My feel is (thought I don't like such expressions in programming) that somehow the os doesn't always handle connections perfectly. Perhaps you could try an array too? Another thing that I've just seen: Why are you setting 0 as a time limit? I remember, in a test I did, I had set a very small one, and the behavior was unpredictable in general.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks,
I saw your post with arrays of sockets etc. and will give that a try.
I guess abandoning sockets and astreams won't eat up too much resource, will it?
I saw the zero in my timeout earlier today and changed it to 3000ms. I even put in a 3 second delay after closing and no changes. The OS seems to leave the port open after it has be "closed" in the app.open comms
  • communications work great
  • shut down server comms
  • Android app trys to recover
  • port "connects" successfully (even though no server is out there)
  • continues like it is connected...
  • after a great while, it will give an Astreams_error
  • if you restart the server, it will communicate again
Thanks,
Rusty
 
Upvote 0
Top