Hi Chiara The best solution is make two different projects one is your socket server and the other is the Django project. is not a good idea connect with socket directly to Django, this will be cause some large delays and in case of connection fails? what is the timeout of the socket connection? is the same of dingo app?
The solutions will be, for example django celery socket server django is independently and the models are updated from celery workers http://www.celeryproject.org/ this is the link of celery, is not so much easy but you can send some emails in this group and i'm sure that someone is ready to help you have a nice day El 27/05/2013, a las 14:14, chi...@tecnoelettricabrianza.it escribió: > Hi there, I'm a really newbye, I've followed the polls tutorial. > 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 python > > import socket #for sockets > import sys #for exit > > #create an INET, STREAMing socket > try: > 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 resolve > print 'Hostname could not be resolved. Exiting' > sys.exit() > > #Connect to remote server > s.connect((remote_ip , port)) > > print 'Socket Connected to ' + host + ' on ip ' + remote_ip > > ## SEND DATA > message = "GET / HTTP/1.1\r\n\r\n" > > try : > #Set the whole string > s.sendall(message) > except socket.error: > #Send failed > print 'Send failed' > sys.exit() > > print 'Message send successfully' > > #RECEIVE DATA > reply = s.recv(4096) > > print reply > > s.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+unsubscr...@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. > > -- 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+unsubscr...@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.