我一直在閱讀套接字示例,但我只能讓 JMP 確認收到請求,但我無法獲取請求的有效負載或消息。有沒有比套接字或調度程序更好的方法來實現非阻塞通信?
一切都在窗戶上。
腳本索引:套接字
使用 JSL 從 API 獲取數據的詳細指南
用於從 JMP、R 和 Python 腳本獲取和記錄消息的套接字通信
我也不明白這個: ((blobdata == Char To Blob( "" )) & (Left(r[2], 11) == "WOULDBLOCK:" ))
r[2] 是什麼? 這些東西的價值不斷索引到不同的東西? 在 python 中,我會期待這樣說:
r = 請求
我的數據字典 = r 。更新({ 'last_jmp_data' :pd.DataFrame(request.json)})
這在 python 中有效以檢索我的數據,但是當我嘗試傳回 JMP 時,唯一打印的是標頭,我無法訪問我發送的 JSON 數據。 我假設我的數據在一些r[#] 項目?
我正在嘗試製作一些可以接收數據的非阻塞的東西,現在我正在使用一個帶有調度程序的 hacky 解決方案來創建工作流並且它確實有效,但它很笨重。
我使用調度程序來安排此功能,這會觸發我的燒瓶服務器,以 JSON 形式接收回數據並更新我的主表更新使 JMP 刪除所有過濾器,因此我們將其記錄到一個字符串中,然後重新應用它,以便用戶不會失去他們正在做的事情。
我想要的是能夠從 javascript 發送請求,並使用 JMP 獲取它:
這是我的 JavaScript 函數,我不需要任何回复,我只希望它轉到 JMP。 以前我使用不同的 JavaScript 解決方法將 JSON 文件寫入我的下載,並使用我的調度程序循環來觀察用戶下載文件夾中的特定 JSON 文件以更新表。
此應用程序是在用戶 PC 上本地運行的單用戶應用程序,不與任何外部資源通信,我只需要在瀏覽器中進行 GUI/某些數據交互,但我仍想將該數據返回到 JMP我的嵌合 JMP/HTML/JS/CS S 應用程序。
我用來從瀏覽器向 python 服務器發送數據的 Javascript 代碼
var xhr = new XMLHttpRequest();
xhr.open("POST", 'http://localhost:8088/passdata', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send([my_json_data]);
跳轉調度程序循環
//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>
我不明白的套接字腳本
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();