Ho letto gli esempi di socket, ma tutto quello che posso fare per JMP è riconoscere di aver ricevuto una richiesta, non riesco a ottenere il payload o il messaggio della richiesta.Esiste un modo migliore dei socket o dello scheduler per ottenere comunicazioni non bloccanti?
Tutto è su Windows.
Indice di scripting: socket
Guida dettagliata sull'utilizzo di JSL per ottenere dati dall'API
Comunicazione socket per ottenere e registrare messaggi da script JMP, R e python
anche io non capisco questo: ((blobdata == Char To Blob( "" )) & (Left(r[2], 11) == "WOULDBLOCK:" ))
cos'è r[2]? Il valore di queste cose continua a indicizzare cose diverse? In Python mi sarei aspettato di dire qualcosa del tipo:
R = domanda
my_data_dict = r .aggiornamento({ 'last_jmp_data' :pd.DataFrame(request.json)})
Funziona in Python per recuperare i miei dati, ma quando provo a tornare a JMP, l'unica cosa che stampa sono le intestazioni, non riesco ad accedere ai dati JSON che ho inviato. Presumo che i miei dati siano in alcuni r[#] articolo?
Sto cercando di creare qualcosa di non bloccante che possa ricevere dati, in questo momento sto usando una soluzione hacky con lo scheduler per creare il flusso di lavoro e FUNZIONA, ma è goffo.
Uso lo scheduler per mantenere questa funzione pianificata, questo colpisce il mio server flask, riceve i dati di ritorno come JSON e aggiorna la mia tabella principale l'aggiornamento fa sì che JMP elimini tutti i filtri, quindi lo registriamo in una stringa e quindi lo riapplichiamo in modo che l'utente non perde quello che stavano facendo.
Quello che mi piacerebbe è poter INVIARE una richiesta da javascript e raccoglierla con JMP:
Questa è la mia funzione JavaScript, non ho bisogno di alcuna risposta, voglio solo che vada su JMP. In precedenza stavo utilizzando una soluzione alternativa JavaScript diversa per scrivere un file JSON nei miei download e utilizzando il mio ciclo di pianificazione per guardare la cartella di download degli utenti per un file JSON specifico con cui aggiornare la tabella.
Questa applicazione è un'app per utente singolo che viene eseguita localmente sul PC dell'utente e non comunica con alcuna risorsa esterna, avevo solo bisogno di effettuare la mia GUI/alcune interazioni di dati in un browser, ma voglio comunque recuperare quei dati in JMP per la mia applicazione chimerica JMP/HTML/JS/CS S.
Codice Javascript che utilizzo per inviare dati al mio server Python dal browser
var xhr = new XMLHttpRequest();
xhr.open("POST", 'http://localhost:8088/passdata', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send([my_json_data]);
Ciclo programmatore 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
);jmp chiama al server python riceve i dati JSON e aggiorna se necessario.
//****************************************************************
//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>
Script socket che non capisco
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();