Android Question Save Tcp connections in DB ( MS SQL or MySQL )

alimanam3386

Active Member
Licensed User
Longtime User
Hi guys

I use Network and RandomAccessFile libraries for communication between clients by tcp protocol , I runned a vps server and connected my clients to this server .Now my question is :

I know I can keep those array of connections in a map but if amount of connections was for example 20K or more what happen ?

Can I save connections ( not just id of users ) in db ? ( I want to save AsyncStreams of users in db )
 
Last edited:

KMatle

Expert
Licensed User
Longtime User
I know I can keep those array of connections in a map but if amount of connections was for example 20K or more what happen ?

Can I save connections ( not just id of users ) in db ? ( I want to save AsyncStreams of users in db )

I don't know what you exactly want to achieve. 20K is not that much on a server (data). Store it in a db. I prefer php plus OKHttpUtils to do so. If you run a B4J app on your server, use RDC or SQLite. There are tons of ways. 20K of active connections could be too much for a single server.

Let us know where your components are running and how. Then we can help more precise.
 
Upvote 0

alimanam3386

Active Member
Licensed User
Longtime User
Connections <> data, you cannot save connections in a database.

How are you implementing the server?

If the connections growed up to 20k for example this map object can it keeps all of those connections inside ?

I use B4J in server side, I used Network and RandomAccessFile libraries :

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Server As ServerSocket
    Private Clients As Map
    Private uId As Int= 0
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.

    Server.Initialize(10733 , "Server")
    Server.Listen

    MainForm.Show
End Sub

Sub Server_NewConnection (Successful As Boolean, NewSocket As Socket)
    If Successful Then
        Dim client As AsyncStreams
        client.Initialize(NewSocket.InputStream , NewSocket.OutputStream , "Client")
        Clients.Put(uId , client) ' save current new connection to map
        uId = uId + 1
        Server.Listen ' Listen for next connection...
    End If
End Sub
.
.
.
 
Last edited:
Upvote 0

alimanam3386

Active Member
Licensed User
Longtime User
The Map can hold millions of objects (or more).

I recommend you to use jServer for real server solutions. It will be much more powerful and reliable.

OK sure Erel , When I use a map object and hold connections inside it , assuming the clients size for this example was 100K , the bellow code it will takes how long to execute ?

B4X:
Dim ws1 = clients.Get("uId_Here") As WebSocket ' <--------  this line how long takes to get the client object ?
ws1.RunFunction("client_Function" , Null)
 
Last edited:
Upvote 0

alimanam3386

Active Member
Licensed User
Longtime User
Yes it is server code, so if we hold 1-10 millions connection in the Map object it can handles all of them, right ?
 
Upvote 0
Top