[Stackoverflow] [Progress OpenEdge ABL] How to use OpenEdge.Net.ServerConnection.ClientSocket?

Status
Not open for further replies.
W

W0lfw00ds

Guest
I was searching for object-oriented way to use Sockets in Progress and found the following document: OpenEdge API Code Documentation

I also found the following source code for the class: ADE-Sourcecode/ClientSocket.cls at master · consultingwerk/ADE-Sourcecode

There doesn't seem to exist any kind of information or tutorials about it.

I tried to map out it's usage by looking at the source codes and came up with this:

Code:
USING OpenEdge.Net.ServerConnection.ClientSocket.
USING OpenEdge.Net.URI.
USING OpenEdge.Net.ServerConnection.ClientSocketConnectionParameters.

CLASS SocketTest:

    CONSTRUCTOR PUBLIC SocketTest():
        
        DEF VAR clientSocket AS ClientSocket NO-UNDO.
        DEF VAR data         AS LONGCHAR NO-UNDO.
        DEF VAR memptr       AS MEMPTR NO-UNDO.

        /* Create the socket object */
        clientSocket = NEW ClientSocket(
            NEW ClientSocketConnectionParameters(
                new URI("scheme???", "192.162.1.50", "9100")
            )
        ).

        /* Subscribe to 'DataReceived'-event??? */
        clientSocket:DataReceived:Subscribe(THIS-OBJECT, OnDataReceived).
        
        /* Connect */
        clientSocket:Connect().

        /* Send data */
        data = "Hello world!".
        COPY-LOB FROM data TO memptr.
        clientSocket:WriteData(memptr).

        /* Wait for response */
        clientSocket:WaitForResponse().
    )

    METHOD PUBLIC OnDataReceived(poSender AS ClientSocket, poEventArgs AS SocketReadEventArgs):

        DEF VAR longcharData AS LONGCHAR NO-UNDO.
        
        /* Convert the received data to longchar */
        COPY-LOB FROM poEventArgs:Data TO longcharData.
    END.
END.

I'm not sure if the above code can actually receive any data, or if the ClientSocket requires some additional configurations? It would be great to use this same piece of code to send and receive data.

I'd also like to know, could we change this from being a "client" into a "server", meaning the client would be the first one connecting to us, and we would then start sending messages to that client etc?

Continue reading...
 
Status
Not open for further replies.
Top