Re: how to use asyncore socket in django views.py
Depending on your needs, Celery could be over-kill. You could create a command that works under manage.py and use it in a cron job. On Tue, Dec 27, 2011 at 5:41 AM, Vovk Donetswrote: > To accepts socket connetction you need always listen some port. Othewise > you will be trying hit a bulls eye when sending data to this port (if you > would listen port only when view was called) View is a function it's not a > webserver that runs and listen to port. > You need to decouple working with sockets from view and place it somewere > outside django > > > 2011/12/27 Vovk Donets > >> For what you need this? >> Maybe you should consider using Celery for doing background jobs. >> >> >> 2011/12/23 Kay >> >>> if I have easy asyncore socket code as follow: >>> >>> >>> -- >>> >>> import socket >>> import asyncore >>> >>> class asysocket(asyncore.dispatcher): >>> >>>def __init__(self,host,port): >>>asyncore.dispatcher.__init__(self) >>>self.create_socket(socket.AF_INET, socket.SOCK_STREAM) >>>self.set_reuse_addr() >>>self.bind((host, port)) >>>self.listen(10) >>>print 'server is waiting for socket connection...' >>> >>>def handle_accept(self): >>>new,addr = self.accept() >>>print 'received from address', addr >>>data = new.recv(1024) >>>print repr(data) >>> >>>def handle_close(self): >>>self.close() >>> >>> server = asysocket('127.0.0.1',1234) >>> asyncore.loop() >>> >>> >>> >>> >>> then how to use this in my django project views.py to let it >>> automatically work for receiving connection >>> >>> while i start the project as "python manage.py runserver [port]"?? >>> >>> thanks >>> >>> >> -- >> *Vovk Donets* >> python developer >> >> skype: suunbeeam >> icq: 232490857 >> mail:donets.vladi...@gmail.com >> www: jetfix.ru >> >> > > > -- > *Vovk Donets* > python developer > > skype: suunbeeam > icq: 232490857 > mail:donets.vladi...@gmail.com > www: jetfix.ru > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- Joseph Slone -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to use asyncore socket in django views.py
To accepts socket connetction you need always listen some port. Othewise you will be trying hit a bulls eye when sending data to this port (if you would listen port only when view was called) View is a function it's not a webserver that runs and listen to port. You need to decouple working with sockets from view and place it somewere outside django 2011/12/27 Vovk Donets> For what you need this? > Maybe you should consider using Celery for doing background jobs. > > > 2011/12/23 Kay > >> if I have easy asyncore socket code as follow: >> >> >> -- >> >> import socket >> import asyncore >> >> class asysocket(asyncore.dispatcher): >> >>def __init__(self,host,port): >>asyncore.dispatcher.__init__(self) >>self.create_socket(socket.AF_INET, socket.SOCK_STREAM) >>self.set_reuse_addr() >>self.bind((host, port)) >>self.listen(10) >>print 'server is waiting for socket connection...' >> >>def handle_accept(self): >>new,addr = self.accept() >>print 'received from address', addr >>data = new.recv(1024) >>print repr(data) >> >>def handle_close(self): >>self.close() >> >> server = asysocket('127.0.0.1',1234) >> asyncore.loop() >> >> >> >> >> then how to use this in my django project views.py to let it >> automatically work for receiving connection >> >> while i start the project as "python manage.py runserver [port]"?? >> >> thanks >> >> > -- > *Vovk Donets* > python developer > > skype: suunbeeam > icq: 232490857 > mail:donets.vladi...@gmail.com > www: jetfix.ru > > -- *Vovk Donets* python developer skype: suunbeeam icq: 232490857 mail:donets.vladi...@gmail.com www: jetfix.ru -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to use asyncore socket in django views.py
Hello~ I need to run the python django project and meanwhile accept the socket connection from somewhere to receive data. But I dont know is this can be done,so any tips if this is possible? thanks~ kay On 12月27日, 下午4時34分, Vovk Donetswrote: > For what you need this? > Maybe you should consider using Celery for doing background jobs. > > 2011/12/23 Kay > > > > > > > > > > > if I have easy asyncore socket code as follow: > > > --- > > --- > > > import socket > > import asyncore > > > class asysocket(asyncore.dispatcher): > > > def __init__(self,host,port): > > asyncore.dispatcher.__init__(self) > > self.create_socket(socket.AF_INET, socket.SOCK_STREAM) > > self.set_reuse_addr() > > self.bind((host, port)) > > self.listen(10) > > print 'server is waiting for socket connection...' > > > def handle_accept(self): > > new,addr = self.accept() > > print 'received from address', addr > > data = new.recv(1024) > > print repr(data) > > > def handle_close(self): > > self.close() > > > server = asysocket('127.0.0.1',1234) > > asyncore.loop() > > > --- > > - > > > then how to use this in my django project views.py to let it > > automatically work for receiving connection > > > while i start the project as "python manage.py runserver [port]"?? > > > thanks > > -- > *Vovk Donets* > python developer > > skype: suunbeeam > icq: 232490857 > mail: donets.vladi...@gmail.com > www: jetfix.ru -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: how to use asyncore socket in django views.py
For what you need this? Maybe you should consider using Celery for doing background jobs. 2011/12/23 Kay> if I have easy asyncore socket code as follow: > > > -- > > import socket > import asyncore > > class asysocket(asyncore.dispatcher): > >def __init__(self,host,port): >asyncore.dispatcher.__init__(self) >self.create_socket(socket.AF_INET, socket.SOCK_STREAM) >self.set_reuse_addr() >self.bind((host, port)) >self.listen(10) >print 'server is waiting for socket connection...' > >def handle_accept(self): >new,addr = self.accept() >print 'received from address', addr >data = new.recv(1024) >print repr(data) > >def handle_close(self): >self.close() > > server = asysocket('127.0.0.1',1234) > asyncore.loop() > > > > > then how to use this in my django project views.py to let it > automatically work for receiving connection > > while i start the project as "python manage.py runserver [port]"?? > > thanks > > -- *Vovk Donets* python developer skype: suunbeeam icq: 232490857 mail:donets.vladi...@gmail.com www: jetfix.ru -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
how to use asyncore socket in django views.py
if I have easy asyncore socket code as follow: -- import socket import asyncore class asysocket(asyncore.dispatcher): def __init__(self,host,port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.set_reuse_addr() self.bind((host, port)) self.listen(10) print 'server is waiting for socket connection...' def handle_accept(self): new,addr = self.accept() print 'received from address', addr data = new.recv(1024) print repr(data) def handle_close(self): self.close() server = asysocket('127.0.0.1',1234) asyncore.loop() then how to use this in my django project views.py to let it automatically work for receiving connection while i start the project as "python manage.py runserver [port]"?? thanks kay -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.