我的Python TCP服务器的日志记录
我需要Python TCP客户端代码的帮助。我现在有了一个基本的TCP客户机代码&我需要在其中添加日志功能,以便在文本文件中查看发送数据的时间和日期。一个用户友好的基本日志功能就可以了。非常感谢你的帮助。我真的很感激我的Python TCP服务器的日志记录,python,sockets,tcp,Python,Sockets,Tcp,我需要Python TCP客户端代码的帮助。我现在有了一个基本的TCP客户机代码&我需要在其中添加日志功能,以便在文本文件中查看发送数据的时间和日期。一个用户友好的基本日志功能就可以了。非常感谢你的帮助。我真的很感激 import socket import sys from thread import * HOST = '' # Symbolic name meaning all available interfaces PORT = 8888 s = socket.socket(so
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()
查看“It应该做您需要的事情”(但您必须阅读文档并自己编写代码:p)您忘记问问题了。这不是一个为我写代码的网站。很抱歉,你在错误的地方。这里没有