de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Sending and receiving data to local server.
PostPosted: Thu Mar 15, 2018 8:51 pm 
Offline
Veteran
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?


Top
 Profile Send private message 
 
 Re: Sending and receiving data to local server.
PostPosted: Fri Mar 16, 2018 2:36 pm 
Offline
Addict
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


Top
 Profile Send private message 
 
 Re: Sending and receiving data to local server.
PostPosted: Sun Mar 18, 2018 12:59 pm 
Offline
Veteran
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.


Top
 Profile Send private message 
 
 Re: Sending and receiving data to local server.
PostPosted: Mon Mar 19, 2018 6:36 pm 
Offline
Veteran
How do you send an HTTP request through sexscripts?


Top
 Profile Send private message 
 
 Re: Sending and receiving data to local server.
PostPosted: Mon Mar 19, 2018 7:06 pm 
Offline
Site Admin
User avatar
Here is a one liner to get the content of a page
Code:
String html = "http://.......".toURL().text


Top
 Profile Send private message 
 
 Re: Sending and receiving data to local server.
PostPosted: Mon Mar 26, 2018 10:25 am 
Offline
Veteran
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.


Top
 Profile Send private message 
 
 Re: Sending and receiving data to local server.
PostPosted: Mon Mar 26, 2018 1:48 pm 
Offline
Veteran
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")


Top
 Profile Send private message 
 
 Re: Sending and receiving data to local server.
PostPosted: Tue Mar 27, 2018 2:33 pm 
Offline
Addict
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


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.