2013-12-19 6 views
0

파이썬 TCP 클라이언트 코드에 도움이 필요합니다. 기본 TCP 클라이언트 코드가 지금 있습니다 & 로깅 기능을 추가해야하므로 보낸 데이터의 날짜가 텍스트 파일에 &으로 표시됩니다. 사용자 친화적 인 기본 로깅 기능이 제공됩니다. 도와 주셔서 감사합니다. 정말 감사. Logger module 밖으로파이썬 TCP 서버 로깅

import socket 
import sys 
from thread import * 

HOST = '' # Symbolic name meaning all available interfaces 
PORT = 8888 

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
print 'Socket created' 

try: 
s.bind((HOST, PORT)) 
except socket.error , msg: 
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1] 
sys.exit() 

print 'Socket bind complete' 

s.listen(10) 
print 'Socket now listening' 

#Function for handling connections 
def clientthread(conn): 
#Sending message to connected client 
conn.send('Welcome to the server. Receving Data...\n') #send only takes string 

#infinite loop so that function do not terminate and thread do not end. 
while True: 

    #Receiving from client 
    data = conn.recv(1024) 
    reply = 'Message Received at the server!\n' 
    print data 
    if not data: 
     break 

    conn.sendall(reply) 

conn.close() 

#now keep talking with the client 



while 1: 
#wait to accept a connection 
conn, addr = s.accept() 
print 'Connected with ' + addr[0] + ':' + str(addr[1])`` 

#start new thread 
start_new_thread(clientthread ,(conn,)) 

s.close() 
+0

당신은 질문을 깜빡입니다. 이것은 나를 쓰는 코드 웹 사이트가 아닙니다. –

+0

죄송하지만 잘못된 장소에 있습니다. 여기에 없습니다 [domyworkforme.com] (http://mattgemmell.com/what-have-you-tried/) – FallenAngel

답변

1

점검 그것은 당신이 무엇을해야한다 (그러나 당신은 문서를 읽고 코드를 직접 작성해야 : P)