B4J Library xSocket - The socket library is fully functional for event and semantic message streams

xSocket is a library wrapped around Socket.d.
Socket.d has a collection of many connection protocols: TCP, UDP and WS. It can be used for MSG, RPC, IM, MQ and other scenarios, and can replace Http, Websocket, gRpc and other protocols. Such as the connection between the mobile device and the server, such as some microservice scenarios, etc.

Main Features​

  • Event-based, each message can be event-routed
  • The so-called semantics is described by the meta-information
  • Stream dependency, where related messages are strung together in a stream
  • Language independent, binary transport (tcp, ws, udp) Support multi-language, multi-platform
  • Disconnection reconnection, automatic connection restoration
  • Multiplexing, allowing multiple request and response messages to run simultaneously on a single connection
  • Two-way communication, single link two-way listening and sending
  • Automatic sharding,Data over 16Mb (configurable) will be automatically split and reassembled (except udp)
  • Simple interface, reactive but with callback interface

* Extends Java: https://drive.google.com/file/d/1AASIjlcINkuU5u607hXxR3c8Y4d7MD7u/view?usp=sharing

* Language supported: B4X, .NET, Javascript, PHP;

There are fully functional xSocket supported:
- Send (Qos0) : Yes
- SendAndRequest (Qos1) : Yes
- SendAndSubscribe (stream) : Yes
- Reply or respond : Yes
- Single connection two-way communication : Yes
- Data sharding : Yes
- Disconnection automatically reconnect : Yes
- Meta information : Yes
- Event(or path): Yes
- StreamId (or message correlation): Yes
- Broker pattern cluster: Yes
- Asynchronous: Async
- Interface experience: Classic
- Basic transport protocol: tcp, udp, ws

* Server Method: (Version 2.12)
- xSession:
- xMessage:
- xStringEntity
- xEntityDefault
- xFileEntity
- xInetSocketAddress
- xMessageDefault
- xRequestStream
- xSendStream

* Client Method: (Version 2.12)
- xClientSocket
- xClientSession
- xEntity

* Server Event:

- OnConnected(session as xSession)
- OnMessage(session as xSession, message as xMessage)
- OnClose(session as xSession)
- OnError(session as xSession, error as String)
- MQOnRequest(session as xSession)
- MQOnMessage(session as xSession, messagex as xMessage)
- MQOnClose(session as xSession)
- MQOnError(session as xSession, error as String)

If you want to compile the application into a .jar file, you need to use SocketD 2.5.10
 

Attachments

  • Javascript Example_v.2.12.zip
    16.7 KB · Views: 65
  • SocketServer Example_v.2.12.zip
    2.9 KB · Views: 83
  • Javascript_xSocket.zip
    14.7 KB · Views: 74
  • b4j_xSocket_2.15.zip
    27.4 KB · Views: 66
  • java_libs_2.5.10.zip
    228.2 KB · Views: 74
  • b4a_xSocket_2.15.zip
    27.4 KB · Views: 74
  • b4j_xSocket_2.16.zip
    32.9 KB · Views: 66
  • b4j_xSocket_2.17.zip
    32.9 KB · Views: 69
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Wow, it looks like huge work !
Are these libs compatible with B4A, B4i too ?
 

tummosoft

Member
Licensed User
Longtime User
xSocket Server: Example with event Path;

xServerSockets:
Sub Process_Globals
    Dim server As xServerSockets 
End Sub

Sub AppStart (Args() As String)
    server.Initialize("server", "ws")
    server.SetCharset("UTF-8") 
   [B] server.EnablePahtListener(True) ' Set enable for listen path[/B]
    server.RequestTimeout(5000)
    server.Start(51042)
    StartMessageLoop 
  
    'open browser and navigate to: http://127.0.0.1:51042/
End Sub

Sub server_OnConnected(session As xSession)
    Log("Server connected: " & session.localAddress)
      
End Sub

Sub server_OnMessage(session As xSession, message As xMessage)
    Log("OnMessage.....")
    Log("Enent: " & message.event)
        If (message.event = "/palidict") Then
            Dim word As String = message.meta("WORD")
            Dim json As String = $"
            <h1>${word}</h1>
            <p>The first line in your HTML code should be the doctype declaration. A doctype tells the browser what version of HTML the page is written in.</p>"$
            Dim entry As xStringEntity
            entry.Initialize(json)
            session.reply(message, entry)
        else if (message.event = "/palidigital") Then
        Log("Reply ready: OK")
            Dim word As String = message.meta("WORD").trim
            Log(word)
        If word.Contains("test") Then
            Dim json As String = $"
            <h1>${word}</h1>
            <p>The first line in your HTML code should be the doctype declaration. A doctype tells the browser what version of HTML the page is written in.</p>"$
            Dim entry As xStringEntity
            entry.Initialize(json)
            session.replyEnd(message, entry)
        Else
            Dim entry As xStringEntity
            entry.Initialize("Wrong word!")
            session.replyEnd(message, entry)
        End If
          
          
        else if (message.event = "/sanskrit") Then
            Dim word As String = message.meta("WORD")         
            Dim json As String = $"
            <h1>${word}</h1>
            <p>The first line in your HTML code should be the doctype declaration. A doctype tells the browser what version of HTML the page is written in.</p>"$
            Dim entry As xStringEntity
            entry.Initialize(json)
            session.reply(message, entry)
        End If
  
End Sub

Sub server_OnError(session As xSession, error As String)
  
End Sub

XSocket Client: Javascript example

B4X:
let isOpen = false;

window.onload = mainDo;

async function open(callback) {  
    let serverUrl = 'sd:ws://127.0.0.1:51042';
    if (!serverUrl) {
        alert('serverUrl cannot be empty!');
        return;
    }
    await SocketD.createClient(serverUrl.trim())
        .config(c => c
            .heartbeatInterval(1000*5)
            .fragmentSize(1024 * 1024)
            .metaPut("test","1"))
        .connectHandler(c=> {
            console.log("connect begin...");
            c.getConfig().metaPut("test","1");
            return c.connect();
        })
        .listen(SocketD.newEventListener()
            .doOnOpen(s=>{
                window.clientSession = s;              
            })
            .doOnMessage((s, m) => {          
        }))
        .open();  
    if (callback) callback();
}

function close(callback) {
    clientSession.close();
    if (callback) callback();
}

function mainDo() {
    open(() => {      
        isOpen = true;
    });
   
    let word = document.getElementById("word").value;
    let push = document.getElementById("btsend");
    let result =  document.getElementById("result");
    push.addEventListener("click", () => {
        if (isOpen) {          
            console.log("send: " + word);
            clientSession.sendAndRequest("/palidigital", SocketD.newEntity(word).metaPut("WORD",word), 100_000).thenReply(reply => {              
                console.log("reply: " + reply.dataAsString());
                result.innerText = reply.dataAsString();
            }).thenProgress((isSend, val,max)=> {
                if(isSend){
                    appendToMessageList('Submit progress', val + "/" + max);
                }
            });
        }
    });
}
 

Attachments

  • Javascript Example_v.2.12.zip
    16.7 KB · Views: 72
Last edited:

tummosoft

Member
Licensed User
Longtime User
Demo02_SendAndSubscribe

* Code in server:

Server:
Sub Process_Globals
    Dim server As xServerSockets 
End Sub

Sub AppStart (Args() As String)
    'config.Initialize
    'config = File.ReadMap(File.DirApp, "config.txt")
    'mysql.Initialize
  
    server.Initialize("server", "ws")
    server.SetCharset("UTF-8") 
    server.EnablePathListener(True)
    server.RequestTimeout(5000)
    server.Start(8602)
      
    StartMessageLoop 
  
    'open browser and navigate to: http://127.0.0.1:51042/
End Sub

Sub server_OnConnected(session As xSession)
    Log("Server connected: " & session.localAddress)
      
End Sub

Sub server_OnMessage(session As xSession, message As xMessage)
    Log(message.event)
    Log(message.isSubscribe)
    If message.isSubscribe Then
        Dim msg As xMessage = message.Message
      
        Dim entry As xEntityDefault = msg.entity
        Log("contet=" & entry.dataAsString)
      
        'entry.Initialize("And you too.")
        'session.reply(message, entry)
      
    End If
  
End Sub

Sub server_OnError(session As xSession, error As String)
  
End Sub

* Code in client:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Dim tcpSocket As xClientSocket
  
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
  
    tcpSocket.Initialize("tcpSocket") 
    tcpSocket.Connect("ws://127.0.0.1:8602/?u=a&p=2")
End Sub

Sub Button1_Click
  
    Dim clientSession As xClientSession = tcpSocket.ClientSession
    Log("Session=" & clientSession.sessionId)
  
    Dim msg As xStringEntity
    msg.Initialize("Hello how are you") 
  
    clientSession.sendAndSubscribe("reply",  msg)
  
End Sub

Sub tcpSocket_OnConnected(session As xSession)
    Log("Session=" & session.sessionId)
  
End Sub
 

Attachments

  • Client_SendAndSubscribe.zip
    29.7 KB · Views: 63
  • Server_Demo02_SendAndSubscribe.zip
    3.2 KB · Views: 68
Last edited:

tummosoft

Member
Licensed User
Longtime User
Demo 3: Send File

Send File Server:
Sub Process_Globals
    Dim server As xServerSockets   
End Sub

Sub AppStart (Args() As String)
    'config.Initialize
    'config = File.ReadMap(File.DirApp, "config.txt")
    'mysql.Initialize
    
    server.Initialize("server", "tcp")
    server.SetCharset("UTF-8")   
    server.EnableSimpleListener(True)
    server.RequestTimeout(5000)
    server.Start(8602)
    
    StartMessageLoop   
    
    'open browser and navigate to: http://127.0.0.1:51042/
End Sub

Sub server_OnConnected(session As xSession)
    Log("Server connected: " & session.localAddress)
        
End Sub

Sub server_OnMessage(session As xSession, message As xMessage)
    Dim filename As String = message.meta(server.META_FILE)
    Log("filename=" & filename)
    If filename <> Null Then
        File.WriteBytes(File.DirApp, "test.zip",message.dataAsBytes)       
    End If
    
End Sub

Sub server_OnError(session As xSession, error As String)
    
End Sub

Send File Client:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Dim tcpSocket As xClientSocket
    
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    
    tcpSocket.Initialize("tcpSocket")   
    tcpSocket.Connect("tcp://127.0.0.1:8602/?u=a&p=2")
    
End Sub

Sub Button1_Click
    
    Dim clientSession As xClientSession = tcpSocket.ClientSession
    Log("Session=" & clientSession.sessionId)
    
    Dim msg As xStringEntity
    msg.Initialize("{user:'b4j'}")       
    clientSession.send("/demo", msg)
    
    Dim filename As String = File.Combine(File.DirApp, "backup.zip")
        
    Dim fileEntry As xFileEntity
    fileEntry.Initialize(filename)
    
    clientSession.send("/demo2", fileEntry)
End Sub

Sub tcpSocket_OnConnected(session As xSession)
    Log("Session=" & session.sessionId)
    
End Sub
 

Attachments

  • Demo03_File_client.zip
    1.5 KB · Views: 63
  • Send_File_server.zip
    3 KB · Views: 64

tummosoft

Member
Licensed User
Longtime User
Demo 4: MQ Server and client

Code in server:
Sub Process_Globals
    Dim server As xServerSockets   
    Dim UserList As Map
End Sub

Sub AppStart (Args() As String)       
    UserList.Initialize
    server.Initialize("server", "udp")
    server.SetCharset("UTF-8")   
    server.EnableSimpleListener(True)
    server.RequestTimeout(5000)
    server.Start(8602)
    
    StartMessageLoop   
    
End Sub

Sub server_OnConnected(session As xSession)
    Log("OnConnected")
    UserList.Put(session.sessionId, session)
End Sub

Sub server_OnMessage(session As xSession, message As xMessage)
    Log("event= " & message.event)
    If message.event = "sensor.template1" Then
        Log("user.created")
        Log("data=" & message.dataAsString)
        
        message.meta("Apcept")
        
    else if message.event = "sensor.template2" Then
        Log("data=" & message.dataAsString)
    End If
End Sub

Sub server_OnClose(session As xSession)
    UserList.Remove(session.sessionId)
End Sub

Sub server_OnError(session As xSession, error As String)
End Sub

Code in client:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Dim tcpSocket As xClientSocket
    
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    
    tcpSocket.Initialize("MqClient")
    tcpSocket.MQConnect("udp://127.0.0.1:8602", 5) 'heartbeatInterval = Increase the heart rate to ensure continuous
    
End Sub

Sub Button1_Click
    
    Dim clientSession As xClientSession = tcpSocket.ClientSession
    Log("Session=" & clientSession.sessionId)
    
    Dim sensor1 As xStringEntity   
    sensor1.Initialize($"{datetime:'${DateTime.Now}', "temp_c": 11,"temp_f": 51.8,}"$)
    clientSession.send("sensor.template1",sensor1)
    
    Sleep(1000)
    
    Dim sensor2 As xStringEntity
    sensor2.Initialize($"{datetime:'${DateTime.Now}', "temp_c": 19,"temp_f": 54.8,}"$)
    clientSession.send("sensor.template2", sensor2)
    
    Sleep(1000)
    
    For i=0 To 5000
        
        clientSession.send("sensor.template2", sensor2)
        
        Sleep(100)
    Next
End Sub
 

Attachments

  • demo4_MQ_client.zip
    1.5 KB · Views: 65
  • Demo4_MQ_sever.zip
    2.9 KB · Views: 64

tummosoft

Member
Licensed User
Longtime User
Demo05: UrlAuth, login

Code in server:
Sub Process_Globals
    Dim server As xServerSockets  
    Dim UserList As Map
End Sub

Sub AppStart (Args() As String)      
    UserList.Initialize
    server.Initialize("server", "tcp")
    server.SetCharset("UTF-8")  
    server.EnableSimpleListener(True)
    server.RequestTimeout(5000)
    server.Start(8602)
   
    StartMessageLoop  
   
End Sub

Sub server_OnConnected(session As xSession)
    Log("OnConnected")
    Dim user As String = session.param("u")
    Dim pass As String = session.param("p")
    Log("user = " & user)
    Log("pass = " & pass)
    If (user <> "b4j") Then
        session.close()
    End If
End Sub

Code in Client:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Dim tcpSocket As xClientSocket
   
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
   
    tcpSocket.Initialize("MqClient")
    tcpSocket.Connect("tcp://127.0.0.1:8602/?u=noear&p=2")
   
End Sub

Sub Button1_Click
   
    tcpSocket.Connect("tcp://127.0.0.1:8602/?u=b4j&p=2")
   
End Sub
 

tummosoft

Member
Licensed User
Longtime User
Demo 6: Remote VPS
In this 6th Demo, there will be an example of a tool that helps automatically install the necessary packages for a VPS hosting. The server and client exchange and send requests to execute shell commands.
For example: You can write a tool to install Mysql, Apache 2, Jetty, Certbot packages, copy database source code and execute data recovery commands... And many more applications.
To use this example you need to add the jFileSupport library: here

Untitled.png


Code in server:
Sub Process_Globals
    Private server As xServerSockets
    Private serverMessage As xMessage
    Private serverSession As xSession
    Private serverAction As Map
    Private shl As Shell
    Private shLinux As Shell
    Private params As List
    Private jFile As jSecuritySupport
End Sub

Sub AppStart (Args() As String)
    
    params.Initialize
    
    
    serverAction = File.ReadMap(File.DirApp, "script.txt")
    
    server.Initialize("server", "tcp")
    server.SetCharset("UTF-8")
    server.EnablePathListener(True)
    server.RequestTimeout(5000)
    server.Start(5042)
    StartMessageLoop
End Sub

Sub server_OnConnected(session As xSession)
    Log("Server connected: " & session.localAddress)
      
End Sub

Sub server_OnMessage(session As xSession, message As xMessage)   
    serverMessage = message
    serverSession = session
    If (message.event = "/installapp") Then
        Dim actionKey As String = message.dataAsString
        Dim actionValue = serverAction.Get(actionKey)
        If (actionValue <> "") Then
            Log("READ ACTION=" & actionValue)
            If (actionValue.Contains("|")) Then
                Dim arrParams() As String = Regex.Split("\|", actionValue)
                For Each param In arrParams
                    params.Add(param)
                Next
                If jFile.isWindows Then
                    shl.Initialize("shl","cmd.exe",params)
                    shl.WorkingDirectory = "C:\Windows\system32"
                    shl.Run(-1)
                else if jFile.isLinux Then                   
                    shLinux.InitializeDoNotHandleQuotes("shLinux",actionValue, Null)
                    shLinux.WorkingDirectory = File.DirApp
                    shLinux.RunWithOutputEvents(-1)
                End If               
            End If
        End If       
    else if (message.event = "/copyfile") Then
        
    else if (message.event = "/database") Then       
    End If
 
End Sub

Sub server_OnError(session As xSession, error As String)
 
End Sub

Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Success")
        Log(StdOut)
        Dim entry As xStringEntity
        entry.Initialize(StdOut)
        
        serverSession.reply(serverMessage, entry)
        
    Else
        Log("Error: " & StdErr)
    End If
    ExitApplication
End Sub

Sub shLinux_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    If Success And ExitCode = 0 Then
        Log("Success")
        Log(StdOut)
        Dim entry As xStringEntity
        entry.Initialize(StdOut)
        
        serverSession.reply(serverMessage, entry)
        
    Else
        Log("Error: " & StdErr)
    End If
    ExitApplication
End Sub

Code in client:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    
    tcpSocket.Initialize("tcpSocket")
    terimal.Initialize
    tcpSocket.Connect("tcp://127.0.0.1:5042/?u=b4j&p=2")
    
    Dim script As String = File.ReadString(File.DirApp, "script.txt")
    txtScript.Text = script
End Sub

Sub tcpSocket_OnConnected(session As xSession)
    Log("Session=" & session.sessionId)
 
End Sub

Sub tcpSocket_OnMessage(session As xSession, message As xMessage)
    Dim msg As xEntityDefault = message.Message
    Log("Mess:" & msg.dataAsString)
    
End Sub


Private Sub btnAction_Click
    Dim clientSession As xClientSession = tcpSocket.ClientSession
    Dim msg As xStringEntity
    msg.Initialize(txtAction.Text)
    
    Dim reply As xEntity = clientSession.sendAndRequest2("/installapp", msg)
    terimal.Append(reply.GetString).Append(CRLF)
    
    txtTerminal.Text = terimal.ToString
End Sub
 

Attachments

  • TummoServer.zip
    2.7 KB · Views: 77
  • RemoteApp.zip
    2 KB · Views: 70

tummosoft

Member
Licensed User
Longtime User
Demo 7: Android example
Android library support: tcp, udp and ws protocol

B4j server:
Sub Process_Globals
    Private server As xServerSockets
    Private serverMessage As xMessage
    Private serverSession As xSession
    Private serverAction As Map
    Private shl As Shell
    Private shLinux As Shell
    Private params As List
    Private jFile As jSecuritySupport
End Sub

Sub AppStart (Args() As String)
    
    params.Initialize
    
    
    serverAction = File.ReadMap(File.DirApp, "script.txt")
    
    server.Initialize("server", "tcp")
    server.SetCharset("UTF-8")
    server.EnablePathListener(True)
    server.RequestTimeout(5000)
    server.Start(51042)
    StartMessageLoop
End Sub

Sub server_OnConnected(session As xSession)
    Log("Server connected: " & session.localAddress)
      
End Sub

Sub server_OnMessage(session As xSession, message As xMessage)   
    If (message.event = "/installapp") Then
        Dim msg As String = message.dataAsString
        Log("Message from Android:" & msg)
        
        Dim reply As xStringEntity
        reply.Initialize("I am fine! Thank a lot")
                
        session.replyEnd(message,reply)
    End If
 
End Sub

Sub server_OnError(session As xSession, error As String)
 
End Sub

Android version:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Dim socketClient As xClientSocket
    'Private server As xServerSockets
    Private ySession As xSession
    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    socketClient.Initialize("socketClient")
    socketClient.B4AConnect("tcp://192.168.1.4:51042/?token=1b0VsGusEkddgr3d")
        
    'server.Initialize("server", "tcp")
    'server.SetCharset("UTF-8")
    'server.EnablePathListener(True)
    'server.RequestTimeout(5000)
    'server.Start(51044)
    Log("---------------------------------")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    
    
    Dim clientSession As xClientSession = socketClient.ClientSession
    Log("Session=" & clientSession.sessionId)
    
    Dim msg As xStringEntity
    msg.Initialize("Hello how are you")
    
    
    Dim reply As xEntity = clientSession.sendAndRequest2("/installapp", msg)
 
    Log(reply.GetString)
End Sub
 

Attachments

  • b4a_xSocket_2.15.zip
    27.4 KB · Views: 74
  • xB4A_example.zip
    2.7 KB · Views: 69
  • b4j_example.zip
    3 KB · Views: 63
  • Like
Reactions: byz

tummosoft

Member
Licensed User
Longtime User
Demo 8: Compressing and decompress data through sockets

In this example I will use the LZString library (see here) to compress data and decompress data when communicating over the socket protocol.

xServerSockets:
Sub Process_Globals
    Private server As xServerSockets
    Private serverMessage As xMessage
    Private serverSession As xSession
    Private serverAction As Map
    Private shl As Shell
    Private shLinux As Shell
    Private params As List
    Private jFile As jSecuritySupport
End Sub

Sub AppStart (Args() As String)
   
    params.Initialize
   
   
    serverAction = File.ReadMap(File.DirApp, "script.txt")
   
    server.Initialize("server", "ws")
    server.SetCharset("UTF-8")
    server.EnablePathListener(True)
    server.RequestTimeout(5000)
    server.Start(51042)
    StartMessageLoop
End Sub

Sub server_OnConnected(session As xSession)
    Log("Server connected: " & session.localAddress)
     
End Sub

Sub server_OnMessage(session As xSession, message As xMessage)  
    If (message.event = "/installapp") Then
           
        Dim lzstring As LZStringCompress
        lzstring.Initialize
        Dim msg As String = lzstring.Decompress4Socket(message.dataAsString)
       
        Log("Message from Android:" & msg)
       
        Dim reply As xStringEntity      
        reply.Initialize(lzstring.Compress4Socket("I am fine! Thank a lot"))
               
        session.replyEnd(message,reply)
    End If
 
End Sub

Sub server_OnError(session As xSession, error As String)
 
End Sub

B4A client:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Dim socketClient As xClientSocket
    'Private server As xServerSockets
    Private ySession As xSession
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    socketClient.Initialize("socketClient")
    socketClient.B4AConnect("ws://192.168.1.4:51042/?token=1b0VsGusEkddgr3d")
       
    'server.Initialize("server", "tcp")
    'server.SetCharset("UTF-8")
    'server.EnablePathListener(True)
    'server.RequestTimeout(5000)
    'server.Start(51044)
    Log("---------------------------------")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
   
   
    Dim clientSession As xClientSession = socketClient.ClientSession
    Log("Session=" & clientSession.sessionId)
   
    Dim msg As xStringEntity
   
    Dim lzstring As LZStringCompress
    lzstring.Initialize
   
    msg.Initialize(lzstring.Compress4Socket("Hello how are you"))
   
   
    Dim reply As xEntity = clientSession.sendAndRequest2("/installapp", msg)
 
    Log(lzstring.Decompress4Socket(reply.GetString))
End Sub
 

Attachments

  • b4j_LZString_2.07.zip
    1.4 KB · Views: 45
  • xB4A_example.zip
    2.7 KB · Views: 57
  • b4j_example.zip
    3.1 KB · Views: 47
Top