cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Vertigo42
Level I

Connecting and listen to a socket

Hi, I'm Jmp 17 user.

I have a python script that is a server that keep sending short messages every 3 sec. 

I'm trying to connect and receive these numbers in jmp. 

I used this HTTP Request example  as reference, but the callbackfn never get called. 

 

callbackfn = function( {x}, 
write ("Message Recieved");
);

//Create a socket
con = Socket();

//Use a specific port on this computer
con << Bind( "localhost", "8081" );

//Tell this socket to be ready for other sockets to connect to it
Write( "\!nlistening on ", (con << getSockName)[3]);
con << Listen();

//When something connects to this socket, call a function to handle
//the connection.  Accept connections for the next 5 minutes.
con << Accept(callbackfn, 30000);

 

The Accept returns  {"Accept" , "ok"}, but the callbackfn is never called. 

I wrote different python client script that shows what I want to do and it works without any problem. 

something like this - 

 

    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    
    try:
        # Connect to the server
        client_socket.connect((host, port))
        print(f"Connected to {host}:{port}")
        
        while True:
            # Receive data from the server
            data = client_socket.recv(1024)
            if not data:
                break
            
            # Print received data
            print(f"Received: {data.decode()}")

 

 

any idea why I can't get it to work on JMP? I can't find any documentation execpt the example above. 

 

Thanks

 

 

 

 

2 REPLIES 2
jthi
Super User

Re: Connecting and listen to a socket

Scripting Index does have more documentation

jthi_0-1734956589663.png

and there is also some in Scripting Guide in JMP Help

-Jarmo
Vertigo42
Level I

Re: Connecting and listen to a socket

Thanks for your reply. 

I already checked the scripting Guide, the scripting index and the samples folder, I coudn't find what I'm looking for. 

 

I'm trying to find a way to get a single number from a server each time it send it, and for now just print it but I don't want to block my JMP app during the waiting. when this will work I'll use this number to update a graph. 

 

I couldn't find how to start a new thread like it is usually done, any other source/direction will be helpfull

 

Thanks

Recommended Articles