Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44699
| References | <4aef55bd-f550-4a3d-b11a-285b6fa9892b@googlegroups.com> |
|---|---|
| Date | 2013-05-04 12:23 +1000 |
| Subject | Re: socket programming |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1282.1367634220.3114.python-list@python.org> (permalink) |
On Sat, May 4, 2013 at 12:13 PM, Pedro <pedro@ncf.ca> wrote: > First - this code constantly loops around an open socket. Is there a way to use something like an interrupt so I don't have to loop constantly to monitor the socket? The accept() call should block. It's not going to spin or anything. If you need to monitor multiple sockets, have a look at select(). > Second, if any part of the program fails execution (crashes) the port often remains open on my windows machine and the only way to close it that i know of is through task manager or by rebooting the machine. Is there an easy way around this problem ? If I don't close the port the program can't open it again and crashes. It remains for a short time to ensure that there's no lurking connections. You can bypass this check by setting the SO_REUSEADDR option - lemme hunt that down in the Python docs, haven't done that in Python for a while... http://docs.python.org/3.3/library/socket.html#socket.socket.setsockopt s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) That should do the job. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
socket programming Pedro <pedro@ncf.ca> - 2013-05-03 19:13 -0700
Re: socket programming Chris Angelico <rosuav@gmail.com> - 2013-05-04 12:23 +1000
Re: socket programming Pedro <pedro@ncf.ca> - 2013-05-03 20:37 -0700
Re: socket programming Chris Angelico <rosuav@gmail.com> - 2013-05-04 13:56 +1000
Re: socket programming Pedro <pedro@ncf.ca> - 2013-05-03 21:03 -0700
Re: socket programming Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-05-04 11:37 +0200
Re: socket programming Chris Angelico <rosuav@gmail.com> - 2013-05-04 20:00 +1000
Re: socket programming Pedro <pedro@ncf.ca> - 2013-05-06 08:54 -0700
Re: socket programming Chris Angelico <rosuav@gmail.com> - 2013-05-07 02:05 +1000
Re: socket programming Arnaud Delobelle <arnodel@gmail.com> - 2013-05-06 19:54 +0100
csiph-web