LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-10-2010, 05:00 PM   #1
xskycamefalling
Member
 
Registered: May 2009
Posts: 43

Rep: Reputation: 15
question about python and sockets.. as the accept line() exacutes program hangs


ok so my question here is i wrote a simple chat type like thing to just see if what i read was working.. anyway

on the server side once it hits the
Code:
clientsocket, address = serversocket.accept()
pythonwin dosent respond untill i actually connect with the client
its a TCP based socket SOCK_STREAM

it doest the same thing when i do it under linux as well

so i guess im just wonder is it because im using TCP that its hanging? is it waiting for the connection? could this be eliminated using udp or is their a way that i could check if a client was trying to connect and if not exacute more commands and then come back to check again after so long like a compare a count variable in a loop or something
any help is much appreciated
 
Old 02-14-2010, 02:44 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,533

Rep: Reputation: 148Reputation: 148
You need to make the socket nonblocking. After you have created it, use
Code:
socket.setblocking(0)
And it should work better. Then you need to select() or any other method to find out when the client actually connects.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[python] reading non-blocking sockets with makefile Ephracis Programming 0 02-25-2009 06:22 PM
Simple sockets program question default5 Programming 10 06-11-2008 08:15 AM
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 09:49 AM
accept input escape new line monil Programming 12 03-18-2005 12:10 PM
stopping a command-line program from python kernelpanicguy Programming 0 09-08-2003 03:29 AM


All times are GMT -5. The time now is 11:41 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration