B4J Question Apache - Thrift class implemetation

Asoka

Member
Licensed User
Longtime User
Hi Everybody!
I want to connect a running local server which communicates with apache thrift. The server uses port: 9096:

1st try (with socket connect)::
Sub POS_Connect
   
    Socket_POS.Connect("::1",9096,0)
   
    Wait For SocketPOS_Connected (Successful As Boolean)
    If Successful Then
        POS_Connected = True  
        Log("Connection successful at: " & DateTime.Time(DateTime.Now))
       
    Else
        POS_Connected=False
        Log("POS Connect Error: " & LastException)  
    End If
End Sub

The connection is successful, but how can I implement or subscribe a thrift class???

2nd try (with MQTT)::
Sub MQTT_Connect_POS
    Dim m As MqttConnectOptions
    m.Initialize("","")
    
    MQTT.Initialize("MQTT","tcp://::1:9096", "AutomataPosSrv")
    MQTT.Connect
    
    Wait For MQTT_Connected (Success As Boolean)
    If Success = True Then
        Log("Client connected!!!")   
        MainForm.Title = "Connected"
        'MQTT.Subscribe("Some Thrift Class", 0)
    Else
        Log(LastException )   
        MainForm.Title = LastException
        
    End If
    
End Sub

What is the correct wa to solve the problem?

Here is a working java sample:

Java:
try {
            Tsocket transport = new TSocket("::1", 9006);
            TProtocol protocol = new TBinaryProtocol(transport);
            transportOpen();
            AutomataPrinterSrv.Client
                client = new AutomataPosSrv.Client(protocol);
                
        } catch (Exception e) {
            e.printStackTrace();
        }


I must write this code in B4j ....
Thank You!
 

Asoka

Member
Licensed User
Longtime User
OK, Thank You!

I forget "MQTT".

Let's see step by step:

There's a ServerSocket to listen::
Listener.Initialize(9190, "Listener")
    Listener.Listen

I connect to the Server Application which Communicates with thrift:

The Server_POS is a socket::
Sub POS_Connect
    
    Socket_POS.Connect("::1",9096,0)
    Wait For SocketPOS_Connected (Successful As Boolean)
    If Successful Then
        POS_Connected = True   
        Log("Connection successful at: " & DateTime.Time(DateTime.Now))
    Else
        POS_Connected=False
        Log("POS Connect Error: " & LastException)   
    End If
End Sub

How can I implement server classes with AsyncStream?
The thrift is known, the protocol: "AutomataSrv.Client"
After sunbscribe the client I must call thrift functions.

The listener is only need for server async messages.

Thank You!
 
Upvote 0
Top