LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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, 06:09 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-10-2010, 07:32 PM   #2
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
I do not know the python API well, but the socket calls will be wrapped to c library calls, which I know well.

If a socket is created using PF_INET and SOCK_STREAM it will be a TCP socket. By default each socket is in a blocking mode. This means if no input is available, the systemcall will block until there is some available. To remove this flag you can use the fcntl syscall (F_SETFL) (see fcntl(2)). In this mode the accept call will simply return if there is no connection request with EAGAIN.

Another method is to poll the socket for input using poll(2).

I hope this helps, although it does not show how to implement it in python.
 
  


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
question about python and sockets.. as the accept line() exacutes program hangs xskycamefalling Programming 1 02-14-2010 03:44 PM
[python] reading non-blocking sockets with makefile Ephracis Programming 0 02-25-2009 07:22 PM
Simple sockets program question default5 Programming 10 06-11-2008 09:15 AM
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 10:49 AM
stopping a command-line program from python kernelpanicguy Programming 0 09-08-2003 04:29 AM


All times are GMT -5. The time now is 07:23 AM.

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