| SexScripts : Sending and receiving data to local server. - https://ss.deviatenow.com:443/viewtopic.php?f=4&t=747 | Page 1 of 1 |
Sending and receiving data to local server. |
cd228 [ Thu Mar 15, 2018 8:51 pm ] |
|---|---|
Hey. I asked a long time ago if there was any way to communicate via serial port through sesxscripts, which didn't seem to be a possibility. So I was wondering - since I have never used server communication before: Can you access a custom or local server through sexscripts? |
|
Re: Sending and receiving data to local server. |
cgut2001 [ Fri Mar 16, 2018 2:36 pm ] |
|---|---|
Hi cd228 it depends on what kind of protocol you want to use. HTTP is quite straightforward as long as you can use 'get-requests' to transfer variables. All you have to do is create a string, containing your request, maybe do some URL-escaping, send it via groovy's 'toURL()' method and evaluate the output. This can be done line by line or on the whole output at once. A short example can be found here: http://mrhaki.blogspot.de/2009/10/groovy-goodness-reading-url-content.html A more complex description can be found here. This also shows how to do http-post-requests. Don't fear it's still very easy and mainly hands-on. https://www.javacodegeeks.com/2013/02/groovy-and-http.html Other tcp-services are just a little more work to do, using groovy's socket-objects. I don't have first hand experience, but I did a short test to netcat on a different machine when reading your question and it worked. The test was a variation of the example here: https://gist.github.com/mgdelacroix/2036ab7c653fa9d7c045 In a more complex setting it may be easier, to write a shellscript, batch-program or whatever and call it from your main-program. An example how to do this can be found in 'Strip or die!' by ptdw. He gives users the option to name an external program controling an e-stim device. This external program is called via useFile(). That way you could even use a serial connection, if you let the user put in a matching program to translate. Regards cgut2001 |
|
Re: Sending and receiving data to local server. |
cd228 [ Sun Mar 18, 2018 12:59 pm ] |
|---|---|
cgut2001 wrote: Hi cd228 it depends on what kind of protocol you want to use. HTTP is quite straightforward as long as you can use 'get-requests' to transfer variables. All you have to do is create a string, containing your request, maybe do some URL-escaping, send it via groovy's 'toURL()' method and evaluate the output. This can be done line by line or on the whole output at once. A short example can be found here: http://mrhaki.blogspot.de/2009/10/groovy-goodness-reading-url-content.html A more complex description can be found here. This also shows how to do http-post-requests. Don't fear it's still very easy and mainly hands-on. https://www.javacodegeeks.com/2013/02/groovy-and-http.html Other tcp-services are just a little more work to do, using groovy's socket-objects. I don't have first hand experience, but I did a short test to netcat on a different machine when reading your question and it worked. The test was a variation of the example here: https://gist.github.com/mgdelacroix/2036ab7c653fa9d7c045 In a more complex setting it may be easier, to write a shellscript, batch-program or whatever and call it from your main-program. An example how to do this can be found in 'Strip or die!' by ptdw. He gives users the option to name an external program controling an e-stim device. This external program is called via useFile(). That way you could even use a serial connection, if you let the user put in a matching program to translate. Regards cgut2001 Cool - thank you very much!. I once had a project where I had sexscripts call a batch program with a command line argument, but the problem was that it was only a one way communication. So I could have sexscripts sending messages to my arduino, but my arduino couldn't send any information back. The reason I need both, is because I want to provide sensory data to sexscripts as well. |
|
Re: Sending and receiving data to local server. |
cd228 [ Mon Mar 19, 2018 6:36 pm ] |
|---|---|
How do you send an HTTP request through sexscripts? |
|
Re: Sending and receiving data to local server. |
doti [ Mon Mar 19, 2018 7:06 pm ] |
|---|---|
Here is a one liner to get the content of a page Code: String html = "http://.......".toURL().text
|
|
Re: Sending and receiving data to local server. |
cd228 [ Mon Mar 26, 2018 10:25 am ] |
|---|---|
Thanks. Currently I am trying to send and get a string through localhost. How could I do that? I want to send a string to 127.0.0.1 through a specified port. |
|
Re: Sending and receiving data to local server. |
cd228 [ Mon Mar 26, 2018 1:48 pm ] |
|---|---|
I have written the following code in python: Code: import socket host = '' port = 8484 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) print("Socked created") try: s.bind((host,port)) except: print("Binding failed") sys.exit() print("Sock has been bounded") s.listen(1) print("Socket Is Ready") while 1: conn,addr = s.accept() data = conn.recv(1024) print(data) http_response = "Hello\r\n" print(http_response) conn.sendall(bytes(http_response.encode('utf-8'))) conn.close() s.close() I can access and get the string "hello" through a web browser, but when I do it through sexscripts I get the error: Error unexpected end of file sexscripts script Code: def html = "http://127.0.0.1:8484".toURL().text
show(html) showButton("Continue") |
|
Re: Sending and receiving data to local server. |
cgut2001 [ Tue Mar 27, 2018 2:33 pm ] |
|---|---|
Not sure if this is the reason but your script doesn't seem to offer http. To me it looks as if it opens a raw tcp-socket, waits for a connection and writes out your data. So you python-script seems to end at transport-layer. In this case it's not strang, groovy/java report an error as they both rely on a real http-connection. I guess you could use one of python's http-server libraries to get it to work. As an alternative you could try to connect to your server via a raw tcp-stream. An example how to do this in groovy is mentioned above. https://gist.github.com/mgdelacroix/2036ab7c653fa9d7c045 |
|
| Page 1 of 1 | All times are UTC + 1 hour [ DST ] |