Created
February 25, 2015 04:51
-
-
Save Craigson/b966dfbf4f13c9d309f4 to your computer and use it in GitHub Desktop.
Python server than computes the x,y, and z-values for the Jacobi Elliptic Equations and sends them in an array to Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://www.binarytides.com/python-socket-server-code-example/ | |
| # https://github.com/Uberi/speech_recognition#readme | |
| #imports for server | |
| import socket | |
| #imports for jacobian functions | |
| import scipy | |
| import math | |
| from scipy.special import ellipj | |
| r = 50 | |
| a = 0.5 | |
| x = [] | |
| y = [] | |
| z = [] | |
| #ellipj returns sn,cn,dn,ph | |
| #compute the jacobi elliptic functions from time t=0 to t=100 | |
| for t in range(0,101): | |
| jacobi = scipy.special.ellipj(t,(a*a)) | |
| x.append(r * (jacobi[0])*math.cos(a*t)) #calculate x-value at time t | |
| y.append(r * (jacobi[0])*math.sin(a*t)) #calculate y-value at time t | |
| z.append(r * jacobi[1]) #calculate z-value at time t | |
| def Main(): | |
| print("server started, listening for connection...") | |
| host = "127.0.0.1" | |
| port = 5001 | |
| s = socket.socket() | |
| s.bind((host,port)) | |
| s.listen(1) | |
| c, addr = s.accept() | |
| print('connection from: ' + str(addr)) | |
| i = 0 | |
| while True: | |
| data = c.recv(1024) | |
| # print(data) | |
| # if not data: | |
| # break | |
| #if data received from processing is an 'A', sent outgoing as x-Value | |
| if data == 'A': | |
| outgoing = x[i] | |
| i+=1 | |
| #if the counter is less than 100, send the value to processing | |
| if i < 101: | |
| c.send(str(outgoing)) | |
| print("sending: " + str(x[i])) | |
| print("length: " + str(i)) | |
| else: | |
| c.close() #if the counter is exceded, close the connection | |
| if __name__ == '__main__': | |
| Main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment