B4J Question using the mysql in a tcpserver

Discussion in 'B4J Questions' started by PassionDEV, Jun 6, 2019.

  1. PassionDEV

    PassionDEV Active Member Licensed User

    i am planing to build a tcpserver using b4j this part is fine but there is a few things in my brain that confuse me

    i will hold about 900 clients on the port each client will be able to insert delete stuff in the mysql database

    now i am asking what should i do in the sql part ? should i give each client its own sql like for example

    Code:
    Sub Class_Globals

        
    Private astream As AsyncStreams
        
    Private Mserv As servermanager
        
    Dim clientsql As SQL
    End Sub
    or i should create a module that connect to sql one time and do the querys inside it with all of this number of clients ?
     
  2. DonManfred

    DonManfred Expert Licensed User

    Setup a jRDC2 and connect all the Clients to it.
    JRDC2 does the Connection to the Database and query/insert/update the data based on the Request.
    i guess you can idetify each client and use client specific values on the data writte to the DB.
     
    PassionDEV and jimmyF like this.
  3. PassionDEV

    PassionDEV Active Member Licensed User

    The clients will have a different databases to connect so maybe each request will connect to a multiple databases
    I will search more in the forum to get the better approach I am still learning the b4j usage
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Sounds like a mistake.

    Build a real server with jServer. You can start with jRDC2 and customize it if needed.
     
    PassionDEV likes this.
  5. PassionDEV

    PassionDEV Active Member Licensed User

    i will do that i am just practice on basics to fully understand what i am doing

    i have created a module like following which makes me ask this question
    Code:
    Sub Class_Globals
    Private fx As JFX

    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize

    End Sub


    Public Sub garabcountrys(dbname As String, dbtable As String, colnm As String)
    Dim SQL1 As SQL
    Dim sqltext As String
    Dim cursor As ResultSet
    SQL1.Initialize2(
    "com.mysql.jdbc.Driver","jdbc:mysql://localhost/"&dbname&"?characterEncoding=utf8","root""root")

    cursor = SQL1.ExecQuery("SELECT * FROM "&dbtable&"")


    Do While cursor.NextRow
    Log(cursor.GetString(colnm))
    Loop

    cursor.Close
    SQL1.Close
    End Sub
    the goal is i wanted to know if i call garabcountrys sub so often based on client request it would be a problem ?
     
  6. OliverA

    OliverA Expert Licensed User

    At minimun, use pooling. See the source for jRDC2 for pool usage. Also, check out ABMaterial. The ABMFeedback app that is included as an example has a DBM code module that uses pooling. Note: You do not have to use the web component of the jServer library in order to use pooling. You should open up your database (either via SQL object or pooling) once at program start. Also, if you want to create a TCP server instead of a web server, then check out the FTP server and how it handles multiple connections.

    Links:
    jRDC2: https://www.b4x.com/android/forum/t...-rdc-remote-database-connector.61801/#content
    ABMaterial: https://www.b4x.com/android/forum/threads/abmaterial-framework-for-webapps.60072/#content
    FTP server: https://www.b4x.com/android/forum/t...d-with-socket-and-asyncstreams.74320/#content
     
    PassionDEV and Erel like this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    The already available implementations, listed above, are way more advanced and powerful than the code you posted. Reinventing the wheel is not always the best idea...
     
    PassionDEV likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice