소켓 예제를 읽어 왔지만 JMP에서 할 수 있는 것은 요청 수신을 확인하는 것뿐입니다. 요청의 페이로드나 메시지를 가져올 수 없습니다.비 차단 통신을 달성하기 위해 소켓이나 스케줄러보다 더 좋은 방법이 있습니까?
모든 것이 창에 있습니다.
기본적으로 내 작업 흐름은 다음과 같습니다.
- JMP로 HTML 페이지 렌더링,
- javascript, html, css를 사용하여 데이터와 상호 작용
- Javascript XMLHTTP 요청을 사용하여 결과를 Python Flask 서버로 전달
- 스케줄러를 통해 jmp로 Flask 서버를 계속 핑하여 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) == "WOULDBLOCK:" ))
r[2]는 무엇입니까? 이러한 것들의 가치는 다른 것들에 대한 색인을 계속 생성합니까? 파이썬에서는 다음과 같은 말을 기대합니다.
아르 자형 = 요청
my_dict.update({ 'last_jmp_data' :pd.DataFrame(요청.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."듣기" 예제는 독립적입니다.
JSL로 웹 서버를 구축하는 것은 상당히 어렵습니다. 이미 JMP에서 Python을 사용하고 있다면 다음을 살펴보십시오. Jelly Video용 프로젝트 파일 특히 NumberServer. 비디오의 이미지를 생성하기 위해 JMP를 여러 개 실행해야 했고 그들이 해야 할 작업을 전달할 방법이 필요했습니다. 번호 서버가 그렇게 했고 JSL 대시보드를 위한 계측을 제공하여 주의가 필요한 시점을 알 수 있었습니다. (그 파이썬 서버는 단일 스레드였으며 동시 요청에 대해 고유 번호를 제공하는 데 좋은 것으로 판명되었습니다. 적어도 나는 중복을 발견하지 못했습니다 ...)
이것은 유망한 자바 스크립트가 기본적으로 웹 소켓도 만들 수 있다고 들립니다.
실행 프로그램이 비차단 방식으로 데이터를 JMP로 가져올 수 있습니까? JMP GUI를 실행하는 외부 프로그램이 있는 동안 차단될 것이라고 생각했습니까?
해당 페이지에서:
Note: If you use Run Program() to launch a GUI program, JMP is inoperable until you close the program
편집: 사실 저는 이미 이것을 다운로드했고 한 번 이해하려고 노력했습니다! 한 번 더 시도하겠습니다.
그런데 지금 내가 하고 있는 일이 아닌가?
웹 브라우저 콘텐츠가 사용자 상호 작용에서 변경되었는지 확인하기 위해 0.5초마다 JMP에서 Flask로 HTTP GET 요청을 스트리밍하는 현재 메커니즘과 비차단 수신기를 만드는 방법인 것 같기 때문에 소켓에만 관심이 있습니다. 나는 JMP가 그 자체로 아무것도 요구하지 않고 플라스크 또는 자바 스크립트에서 JMP로 이벤트를 PUSH하기를 바라고 있습니다.
check_downloads_over_ip() 함수 //http get
그리고 get_remote_update(). // 스케줄러 루프
get_remote_update()는 check_downloads 기능을 "실시간"으로 만들기 위한 메커니즘으로 스케줄러에서 지속적으로 예약된 상태로 유지합니다.
문제는 스케줄러가 비 차단 동작을 생성하는 매우 우아한 방법이 아니라는 것입니다.
저는 JMP가 (차단되지 않는 방식으로) 수신 대기하도록 하고 싶습니다. 그런 다음 브라우저에서 직접 javascript의 http 요청을 JMP로 푸시하고 플라스크 서버를 완전히 제거할 수 있습니다.
중요한 점은 JMP가 서버에서 데이터를 끌어온 다음 응답으로 작업할 수 있는 도구를 가지고 있지만 JMp가 먼저 아무 것도 요청하지 않고 브라우저나 서버에서 JMP로 이벤트를 푸시할 수 있다는 것입니다.
내 앱에서 모든 IP를 제거하고 비디오를 게시하여 내가 원하는 것을 더 명확하게 할 것입니다.
RunProgram은 N개의 외부 프로그램을 동시 및 비동기식으로 실행할 수 있습니다. JMP가 유휴 상태인 경우 N RunPrograms는 stdin에서 데이터를 수신할 때 ReadFunction() 스크립트를 실행할 수 있으며 stdout을 통해 데이터를 쓸 수 있습니다. Python이 RunProgram이 실행 중인 프로그램인 경우 Python의 stdin은 RunProgram의 stdout이고 ...stdout...stdin입니다. (N은 아마도 10초보다 클 수 없습니다.)
RunProgram은 Excel과 같은 것을 실행할 수 있지만 차단됩니다. RunProgram은 stdin 및 stdout이 있는 명령줄 프로그램에 훨씬 좋습니다. cmd.exe를 사용하거나 다음을 사용할 수 있습니다. 플링크 원격 Linux 시스템에서 셸을 엽니다. 또는 C나 Python 또는 자신의 다른 언어 프로그램을 실행할 수도 있습니다.
RunProgram에는 두 가지 작업 모드가 있습니다. ReadFunction("text")이 있으면 차단 모드에서 실행되어 모든 stdout을 수집하고 문자열을 반환합니다. 그렇지 않으면 비 차단 모드에서 실행되고 RunProgram 개체를 반환합니다. 당신이 지켜야 할 변수에(그렇지 않으면 프로세스가 완료되기 전에 삭제됩니다.)
RunProgram 개체에 보낼 수 있는 명령은 몇 가지뿐입니다. 연결에 대해 물어보고 데이터를 보내고 받을 수 있습니다.
저는 보통 스케줄러를 사용하지 않습니다. 왜냐하면 스케줄러는 창이 열려 있기를 원하기 때문입니다. 뉴스 피드 . 동일한 문서에서는 CMD 시작 명령을 사용하여 차단 동작 없이 msedge 브라우저를 실행하는 방법을 보여줍니다.
JSL(같은 글)로 서버를 작성했지만 파이썬이나 파이썬+플라스크 솔루션을 사용하는 것이 훨씬 낫다고 생각합니다. 플라스크를 사용하는 경우 다음을 시도하십시오. RunProgram이 Python+flask 코드를 시작하도록 하고 RunProgram에 Python 코드(stdin/stdout)와 통신할 수 있도록 readfunction 및 writefunction에 일부 로직을 제공합니다. Python 코드에서 JMP와 대화할 스레드를 추가합니다. 플라스크 서버에는 http 요청을 처리하는 자체 스레드가 있습니다. 서버가 무언가를 jmp에 푸시해야 하는 경우 JMP에 무언가를 인쇄할 JMP 스레드에 이벤트 신호를 보내야 합니다. JMP를 수신 대기하는 판독기 스레드인 Python 스레드가 하나 더 필요할 수 있습니다.