I'm looking for a way to dinamically create web-pages that will send and receive message to a TCP/Ip server that use a custom protocol for communication.
I've got the python code that handle the communication and I kindly ask you some advice on the right way to do it:
-- 1)create a model with the fields of data to be sent and received from server
2)create in the view: 1) function that handle the connection
2) function that send data
3) function that receive data
3) create a template with model's fields
Is this right?
Below the python code that is now standalone and working to connect to server.
#Socket client in pythonimport socket #for socketsimport sys #for exit#create an INET, STREAMing sockettry:s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)except socket.error:print 'Failed to create socket'sys.exit()print 'Socket Created'host = '192.168.1.1';port = 35000;try:remote_ip = socket.gethostbyname( host )except socket.gaierror:#could not resolveprint 'Hostname could not be resolved. Exiting'sys.exit()#Connect to remote servers.connect((remote_ip , port))print 'Socket Connected to ' + host + ' on ip ' + remote_ip## SEND DATAmessage = "GET / HTTP/1.1\r\n\r\n"try :#Set the whole strings.sendall(message)except socket.error:#Send failedprint 'Send failed'sys.exit()print 'Message send successfully'#RECEIVE DATAreply = s.recv(4096)print replys.close()
Please let me know about it. Thanks. BR.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment