ソケットの例を読んでいましたが、JMP にできるのはリクエストの受信を確認することだけで、リクエストのペイロードやメッセージを取得できません。ノンブロッキング通信を実現するソケットやスケジューラよりも優れた方法はありますか?
すべてはWindows上にあります。
基本的に私のワークフローは次のとおりです。
- JMP を使用して HTML ページをレンダリングします。
- JavaScript、HTML、CSSを使用してデータを操作する
- Javascript XMLHTTP リクエストを使用して結果を Python Flask サーバーに渡します
- スケジューラー経由で jmp を使用して Flask サーバーに継続的に ping を実行し、Flask サーバーに待機中のデータがあるかどうかを確認します。データがある場合は、Python がデータを返し、JMP がそれを応答として取得します。データがない場合、jmp は文字列 ' を取得します。アップデートはありません」と私はただ戻る。
- サーバーから取得したデータで JMP テーブルを更新します。
ステップ3と4を削除し、リクエストを受信したときにコールバックを起動し、そのリクエスト内のデータを使用するjmpのノンブロッキング・リスナーを備えたJavaScript xmlhttpリクエストを使用して、ブラウザからjmpにデータを直接PUSHしたいと考えています。テーブルを更新します。 現在、私のノンブロッキング「リスナー」は、スケジューラーをスパム送信するループになっています。
これまでに読んだもの:
スクリプトインデックス: ソケット
JSL を使用して API からデータを取得するための詳細なガイダンス
JMP、R、および Python スクリプトからメッセージを取得してログに記録するためのソケット通信
これも理解できません: ((blobdata == Char To Blob( "" )) & (Left(r[2], 11) == "WOUULDBLOCK:" ))
r[2]とは何ですか? これらの値は、さまざまなものにインデックスを付け続けますか? Python では次のようなことを言うことを期待しています:
r = リクエスト
my_dict.update({ 'last_jmp_data' :pd.DataFrame(request.json)})
これはPythonでデータを取得するために機能しますが、JMPに戻そうとすると、出力されるのはヘッダーだけであり、送信したJSONデータにアクセスできません。 私のデータはどこかにあると思いますr[#]項目?
データを受信できるノンブロッキングなものを作成しようとしています。現在、スケジューラーを使用してハッキングなソリューションを使用してワークフローを作成しており、実際には機能しますが、不格好です。
スケジューラーを使用してこの関数のスケジュールを維持します。これがフラスコサーバーにヒットし、データをJSONとして受信し、メインテーブルを更新します。更新によりJMPはすべてのフィルターを削除するため、それを文字列に記録してから、それを再適用します。彼らがしていたことを失うことはありません。
私が望んでいるのは、JavaScript からリクエストを送信し、それを JMP で取得できるようにすることです。
これは私の JavaScript 関数です。応答は必要ありません。JMP に送信するだけです。 以前は、別の JavaScript 回避策を使用して JSON ファイルをダウンロードに書き込み、スケジューラー ループを使用して、テーブルを更新する特定の JSON ファイルのユーザー ダウンロード フォルダーを監視していました。
このアプリケーションは、ユーザーの PC 上でローカルに実行されるシングル ユーザー アプリであり、外部リソースと通信しません。ブラウザーで GUI と特定のデータのやり取りを行う必要があるだけですが、そのデータを JMP に戻したいと考えています。私のキメラ JMP/HTML/JS/CSS アプリケーション。
ブラウザから Python サーバーにデータを送信するために使用する Javascript コード。これを JMP に直接送信し、到着時に更新したいと考えています。
var xhr = new XMLHttpRequest();
xhr.open("POST", 'http://localhost:8081', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send([my_json_data]);
Jmp スケジューラ ループ
//scheduled loop to ping python local server and see if it's time to update:
get_remote_update = Function({},
s = Schedule(.25,
//show("remote update fn");
//check_downloads_folder(); // old routine that was watching download folder
check_downloads_over_ip();
get_remote_update(); //loops by scheduling the event again
);Python サーバーへの jmp 呼び出しは JSON データを受信し、必要に応じて更新します。
//****************************************************************
//check_downloads_OVER_IP();
//****************************************************************
// EXPLORE THIS dt = Open( Char To Blob( request << Send() ), "JSON" );
// see if we can just get the response back into a table without creating it with the weird JMP thing
check_downloads_over_ip = Function({},
request = New HTTP Request(
URL("localhost:8088/get_update"),
Method("Post"),
Timeout( .5 ),
);
data=request << Send;
if((data != "No Update" > 0) & ( isempty(data) != 1 ),
obj = JSON:Parse( data );
dt = JSON:Make Table(obj);
dt << show window(0);
temp_dtf = CHAR(dtf <<GET script=""></GET>
ソケットスクリプト、特にこの部分がわかりません: // 受信した内容をログに書き込みます
ログにヘッダーが出力されますが、送信した JSON データにアクセスできません。
Names default to here( 1 );
//Table to hold received data
dtLog = New Table( "Log",
New Column( "Time", Numeric, "Continuous", Format( "m/d/y h:m:s", 23, 0 ),
Input Format( "m/d/y h:m:s", 0 ) ),
New Column( "Client", Character, "Nominal" ),
New Column( "Message", Character, "Nominal" )
);
//Wait for and get data from remote machine
receivedata = Function( {c, waittime = 1, waitcount = 10},
//Varaible to store data received from remote machine
blobdata = Char To Blob( "" );
//Make socket is connected
r = c << GetPeerName();
//While receiving data or waiting to receive data
i = 0;
While(
(
(r[2] == "ok") |
((blobdata == Char To Blob( "" )) & (Left(r[2], 11) == "WOULDBLOCK:" ))
) &
(i < waitcount),
i++;
//Get data
r = c << recv( 100000 );
//If no data is received yet, wait
If(Left(r[2], 11) == "WOULDBLOCK:", Wait( waittime ) );
//Write whatever is received to the log
show("writing to log now");
Write( Blob to Char( r[3] ) );
show("Done writing to log now");
//join data to whatever is already received
blobdata = blobdata || r[3];
);
return( blobdata );
);
//Get log info from remote machine, store it in a data table
processlogconnection = function( {c},
//New row in log table
dtLog << Add Rows( 1 );
rowout = N Rows( dtLog );
Column( dtLog, "Time" )[rowout] = Today();
//Get computer name of remote machine
r = c << GetPeerName();
Column( dtLog, "Client" )[rowout] = r[3];
//Get message from the remote machine
Column( dtLog, "Message" )[rowout] = Blob to Char( receivedata( c ) );
//Close the connection
c << Close;
);
//Function to accept conections from remote machine, calls another
//function to handle communication with that machine
callbackfn = function( {x},
//Call another function with the connection returned from the Accept message
If( x[2] == "ok", processlogconnection( x[4] ) );
);
//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();
//Verify that the connection is active
con << getsockname;
//When something connects to this socket, call a function to handle
//the connection. Accept connections for the next 5 minutes.
con << Accept(callbackfn, 30000);
//Now messages can be sent to this connection.
//When all done, close the connection
//con << close();
JMP の HTTP リクエストを使用して Flask サーバーに ping を送信できます。 そうすれば、やりたいことの複雑さが軽減されます。
HTTP リクエスト (GET 操作を想定しています) でサーバーにクエリを実行し、戻り値 (JSON ペイロードなど) で応答を直接読み取り、準備ができたら、再度 HTTP リクエスト (おそらく GET として) を使用して、からのデータを処理できます。サーバー。 もちろん、HTTP/HTTPS ではなくソケットを使用している場合は、ソケットのアプローチを使い続ける必要があります。
また、JMP のソケットは https をサポートせず、http のみをサポートします。 これらは低レベルのソケット コードを囲むかなり薄いラッパーであり、http プロトコルについては何も知りません。すべて自分で構築する必要があります。 完全な例はスクリプト索引にあります。
The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.The "listen" example is self-contained.「listen」の例は自己完結型です。
JSL で Web サーバーを構築するのは非常に困難です。 すでに JMP の Python を使用している場合は、以下を参照してください。 Jelly Video のプロジェクト ファイル特にNumberServer。 ビデオ内の画像を生成するには JMP の複数のコピーを実行する必要があり、必要な作業をそれらのコピーに渡す方法が必要でした。 ナンバー サーバーはそれを実行し、JSL ダッシュボードに計測機能を提供して、何か注意が必要なときにそれを知ることができるようにしました。 (その Python サーバーはシングルスレッドだったと思います。これは、同時リクエストに対して一意の番号を提供するのに適していることが判明しました。 少なくとも私は重複に気づいたことはありません...)
これは、JavaScript が WebSocket をネイティブに作成できることを期待させてくれます。
プログラムを実行すると、非ブロック的な方法でデータを JMP に取得できますか? 外部プログラムを実行している間、JMP GUI がブロックされるのではないかと思いましたか?
そのページから:
Note: If you use Run Program() to launch a GUI program, JMP is inoperable until you close the program
編集: 実はこれをすでにダウンロードして、一度理解しようとしました。 もう一度試してみます。
それが今私がやっていることではないでしょうか?
私がソケットに興味があるのは、Web ブラウザーのコンテンツがユーザーの操作によって変更されたかどうかを確認するために、0.5 秒ごとに JMP から Flask に HTTP GET リクエストをストリーミングする現在のメカニズムに対して、ノンブロッキング リスナーを作成する方法であるように見えるためです。 JMPが単独で何かを要求することなく、フラスコまたはJavaScriptからJMPにイベントをPUSHしたいと考えています。
check_downloads_over_ip() 関数 //http get
そして get_remote_update()。 // スケジューラループ
get_remote_update() は、check_downloads 関数を「リアルタイム」にするメカニズムとしてスケジューラで常にスケジュールされた状態に保ちます。
問題は、スケジューラが非ブロッキング動作を生成するためのあまり洗練された方法ではないことです。
JMP が (非ブロック的な方法で) 待機して待機し、ブラウザ内の JavaScript から JMP に直接 http リクエストをプッシュして、flask サーバーを完全に排除したいと考えています。
重要なのは、JMP にはサーバーからデータを PULL して応答を処理するツールがありますが、JMp が最初に何も要求せずにブラウザまたはサーバーから JMP にイベントを PUSH できるかどうかです。
アプリからすべての IP を削除し、目的をより明確にするためにビデオを投稿します。
RunProgram は、N 個の外部プログラムを同時に非同期に実行できます。 JMP がアイドル状態の場合、N 個の RunProgram は stdin でデータを受信するときに ReadFunction() スクリプトを実行でき、stdout 経由でデータを書き込むことができます。 RunProgram が実行しているプログラムが Python の場合、Python の stdin は RunProgram の stdout であり、...stdout...stdin となります。 (N はおそらく数 10 を超えることはできません。)
RunProgram は Excel などを実行できますが、ブロックされます。 RunProgram は、stdin と stdout を使用するコマンド ライン プログラムにはるかに適しています。 cmd.exe を使用することもできますし、チクチクリモート Linux マシンでシェルを開きます。 あるいは、C、Python、またはその他の独自の言語プログラムを実行することもできます。
RunProgram には 2 つの動作モードがあります。ReadFunction("text") がある場合はブロッキング モードで実行され、すべての stdout を収集して文字列を返します。 それ以外の場合は、ノンブロッキング モードで実行され、RunProgram オブジェクトが返されます。保存しなければならないもの変数内 (そうしないと、プロセスが完了する前に削除されます)。
RunProgram オブジェクトに送信できるコマンドはわずかです。接続について問い合わせたり、データを送受信したりできます。
スケジューラはウィンドウを開いたままにする必要があるため、通常はこの種のことには使用しませんが、次を参照してください。ニュースフィード。 同じ記事では、CMD 開始コマンドを使用して、ブロック動作を行わずに msedge ブラウザを実行する方法を示しています。
私は JSL でサーバーを作成しました (同じ記事) が、Python または Python+flask ソリューションを使用する方がはるかに優れていると思います。 flask を使用する場合は、これを試してください。RunProgram に Python+flask コードを起動させ、RunProgram の readfunction と writefunction に Python コード (stdin/stdout) と通信するためのロジックを与えます。 Python コードに、JMP と通信するためのスレッドを追加します。 フラスコ サーバーには、http リクエストを処理するための独自のスレッドがあります。 サーバーが何かを jmp にプッシュする必要がある場合は、JMP に何かを出力するイベントを JMP スレッドに通知する必要があります。 JMP をリッスンするリーダー スレッドである Python スレッドがもう 1 つ必要になる場合があります。