<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Connecting and listen to a socket in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Connecting-and-listen-to-a-socket/m-p/824869#M100470</link>
    <description>&lt;P&gt;Hi, I'm Jmp 17 user.&lt;/P&gt;&lt;P&gt;I have a python script that is a server that keep sending short messages every 3 sec.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to connect and receive these numbers in jmp.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used this&amp;nbsp;&lt;A href="https://community.jmp.com/t5/Discussions/How-can-I-listen-for-HTTP-requests-and-then-fire-a-callback/td-p/643450" target="_self"&gt;HTTP Request example&lt;/A&gt;&amp;nbsp; as reference, but the callbackfn never get called.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;callbackfn = function( {x},&amp;nbsp;
write ("Message Recieved");
);

//Create a socket
con = Socket();

//Use a specific port on this computer
con &amp;lt;&amp;lt; Bind( "localhost", "8081" );

//Tell this socket to be ready for other sockets to connect to it
Write( "\!nlistening on ", (con &amp;lt;&amp;lt; getSockName)[3]);
con &amp;lt;&amp;lt; Listen();

//When something connects to this socket, call a function to handle
//the connection.&amp;nbsp; Accept connections for the next 5 minutes.
con &amp;lt;&amp;lt; Accept(callbackfn, 30000);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Accept returns&amp;nbsp; {"Accept" , "ok"}, but the callbackfn is never called.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote different python client script that shows what I want to do and it works without any problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;something like this -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    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()}")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any idea why I can't get it to work on JMP? I can't find any documentation execpt the example above.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Dec 2024 12:18:11 GMT</pubDate>
    <dc:creator>Vertigo42</dc:creator>
    <dc:date>2024-12-23T12:18:11Z</dc:date>
    <item>
      <title>Connecting and listen to a socket</title>
      <link>https://community.jmp.com/t5/Discussions/Connecting-and-listen-to-a-socket/m-p/824869#M100470</link>
      <description>&lt;P&gt;Hi, I'm Jmp 17 user.&lt;/P&gt;&lt;P&gt;I have a python script that is a server that keep sending short messages every 3 sec.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to connect and receive these numbers in jmp.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used this&amp;nbsp;&lt;A href="https://community.jmp.com/t5/Discussions/How-can-I-listen-for-HTTP-requests-and-then-fire-a-callback/td-p/643450" target="_self"&gt;HTTP Request example&lt;/A&gt;&amp;nbsp; as reference, but the callbackfn never get called.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;callbackfn = function( {x},&amp;nbsp;
write ("Message Recieved");
);

//Create a socket
con = Socket();

//Use a specific port on this computer
con &amp;lt;&amp;lt; Bind( "localhost", "8081" );

//Tell this socket to be ready for other sockets to connect to it
Write( "\!nlistening on ", (con &amp;lt;&amp;lt; getSockName)[3]);
con &amp;lt;&amp;lt; Listen();

//When something connects to this socket, call a function to handle
//the connection.&amp;nbsp; Accept connections for the next 5 minutes.
con &amp;lt;&amp;lt; Accept(callbackfn, 30000);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Accept returns&amp;nbsp; {"Accept" , "ok"}, but the callbackfn is never called.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote different python client script that shows what I want to do and it works without any problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;something like this -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    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()}")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any idea why I can't get it to work on JMP? I can't find any documentation execpt the example above.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2024 12:18:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Connecting-and-listen-to-a-socket/m-p/824869#M100470</guid>
      <dc:creator>Vertigo42</dc:creator>
      <dc:date>2024-12-23T12:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting and listen to a socket</title>
      <link>https://community.jmp.com/t5/Discussions/Connecting-and-listen-to-a-socket/m-p/824880#M100471</link>
      <description>&lt;P&gt;Scripting Index does have more documentation&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1734956589663.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/71503iF5E0A1C51FB28DA6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1734956589663.png" alt="jthi_0-1734956589663.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and there is also some in &lt;A href="https://www.jmp.com/support/help/en/18.0/#page/jmp/use-sockets-in-jsl.shtml#" target="_blank" rel="noopener"&gt;Scripting Guide in JMP Help&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Dec 2024 12:23:51 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Connecting-and-listen-to-a-socket/m-p/824880#M100471</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-12-23T12:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Connecting and listen to a socket</title>
      <link>https://community.jmp.com/t5/Discussions/Connecting-and-listen-to-a-socket/m-p/825182#M100515</link>
      <description>&lt;P&gt;Thanks for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already checked the scripting Guide, the scripting index and the samples folder, I coudn't find what I'm looking for.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't find how to start a new thread like it is usually done, any other source/direction will be helpfull&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2024 08:35:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Connecting-and-listen-to-a-socket/m-p/825182#M100515</guid>
      <dc:creator>Vertigo42</dc:creator>
      <dc:date>2024-12-26T08:35:14Z</dc:date>
    </item>
  </channel>
</rss>

