Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Python socket programming

Status
Not open for further replies.

iainms

Technical User
Oct 24, 2005
3
GB
Hi, i'm fairly new to python (just started using it today infact), and fairly new to programming for that matter.

For my first python program, i've managed to code a simple chat program that allows text to be sent to and from computers on my network. I've also created a GUI for this program using wxpython and it seems to work ok.

However, I'm stumped when I try to integrate my chat program into the GUI i created for it. The problem is that wherever I insert the code to listen for a connection (s.listen(1)) my GUI hangs until it gets a connection request. Is there any way of getting my program to listen for a TCP connection without locking up my GUI?

Any help would be appreciated..
 
I'm not positive and I porbably don't know much more Python than you do, but If I were trying to do this, then I would split off the listener as a seperate thread then have it signal back to the GUI thread when something came through on the port it was listening to.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thanks for the suggestion. I think you're right but I dont have the slightest clue about multi-threaded applications. Oh well, better get google-ing.
 
did you try s.setblocking(0)?

Yeah i did but it returns :
socket.error: (10035, 'The socket operation could not complete without blocking')

I dont think i'm doing it right. Where do I put that line of code, is it before or after s.listen(1)??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top