2016-07-14 6 views
0

私はソケットプログラミングを手に入れようとしています.Belowは私のサーバー側のコードで、ここにはクライアントサイドのコードは似ていません。スレッド(tryブロック内)が私のコンソールと呼ばれるとすぐにo/pが消えます。 Windows 7のDOSでこれを処理する方法がわかりません。既存のディスカッションを読み込もうとしましたが、それほど有用ではありませんでした。どんな助けもありがたい。ありがとう。ラヴィ。 コードブロック:Python - Threading - Console o/pディッパー

import socket 
import sys 
import time 
import thread 

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
server_address = ('localhost', 15000) 
sock.bind(server_address) 
sock.listen(1) 
connection, client_address = sock.accept() 
Servername = raw_input('Starting the chat(enter "QUIT" to discontinue), Please enter your name: ') 

def Server_outgoing(): 
    while True: 
     outgoing_message_server = raw_input() 
     if (outgoing_message_server == 'Quit' or outgoing_message_server == 'quit' or outgoing_message_server == 'QUIT'): 
      print "Server has decided to abort the chat - Bye bye" 
      break 
     print "######################################################################" 
     print >>sys.stderr, '"%s" : Printing outgoing message from Server "%s"' % (Servername, outgoing_message_server) 
     print "######################################################################" 
     connection.sendall(outgoing_message_server)  
try: 
    thread.start_new_thread(Server_outgoing,()) 
finally: 
    connection.close() 
+0

あなたが本当に*または*ブロッキングをスレッド、ソケットを理解していないように見えます。私は、*ここで物事を説明するのを助けるかもしれないものを集めました(https://draftin.com/documents/896689?token=ZT_Lt2VVDbG0UjxQpp4IJN85JrvNEBSh1ulFIcyuRl9EbbsCwRDRmqWsGNP-G3awHfbxc6tnU5oppofHGWeEA5U)。私は実際にそこにスレッドの例を持っていませんが、それは本当に必要ではないためです。 –

答えて

0

[OK]をguys..Thisは働いていた..:

thread1 = Thread(target=Server_outgoing, args=()) 
    thread1.start() 
    thread1.join()