Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

Connection acception with confirmation


Hi, i'm new in Python and i'm trying to write some server which can
confirm connection from client.
Here is a part of code:

import sys
import threading
from socket import *

class TelGUI(threading.Thread):
        def __init__(self):
                threading.Thread.__init__(self)

        def run(self):
                s = socket(AF_INET, SOCK_STREAM)
                s.bind(('',8900))
                s.listen(5)
                while 1:
                        client,addr = s.accept()
                        print addr
                        print "Or u want to accept connection from this host? [y/n]"
                        opt = sys.stdin.read(1)
                        if opt == 'y':
                                #establish
                        else: s.close() #reject

def main():
        app = TelGUI()
        app.start()

        print "Menu"
        while 1:
                #some menu operations
                op = sys.stdin.read(1)
                if op == 'x':
                        break

if __name__ == "__main__":
        main()

maybe someone have some ideas how to block first stdin in main
function and get stdin from the thread when here is a new connection?
Thanks

no`name` wrote in news:1180462910.584445.256400@j4g2000prf.googlegroups.com
in comp.lang.python:

> maybe someone have some ideas how to block first stdin in main
> function and get stdin from the thread when here is a new connection?

No, but you could instead use a Queue:

        http://docs.python.org/lib/module-Queue.html

so that your main thread reads stdin and then uses an instance
of Queue to post the 'y's and 'n's it recives to your server
thread.

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc