チャットプログラムのコードベースをSSL/TLSとマルチスレッドで書き留めます。誰かがpythonネットワークpragramで私を助けることができますか?
3つのことがあります。
1.クライアントがクライアントのIDとIPまたはネットワークインターフェイス情報、ネットワーク情報を接続しているとき。
2.クライアントがメッセージを送信する際には、毎回このフォーム([Client ID @ connect IP] Message)に従わなければなりません。
3.youは、クライアントとサーバーのプログラムとのフローチャートを示し、説明する必要があります。
それはネットワークプログラミングの私の最終試験です。それは私にとっては難しいことです。私はコードを書くことができませんでした。だから私は何もせずに論文を提出しなければならない。私はやり方がわからない。誰かがプログラムのコーディング方法を説明することができますか?
私のコードは
server.py
import socket
import thread
print '---python chatting program---'
host = ''
port = 27332
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.listen(1)
users = []
def service(conn):
try:
name = conn.recv(1024)
str = '*' + name + ' is entered.*'
while conn:
print str
for each in users:
each.send(str)
str = name + ' : ' + conn.recv(1024)
except:
users.remove(conn)
str = '*' + name + ' is out.*'
print str
if users:
for each in users: each.send(str)
# thread.start_new_thread(service,())
while 1:
conn, addr = s.accept()
global users
users.append(conn)
thread.start_new_thread(service, (conn,))
pass
client.py
import socket
import thread
def handle(socket):
while 1:
data = socket.recv(1024)
if not data:
continue
print data
print 'handler is end.'
host = '127.0.0.1'
port = 27332
print 'enter your name.'
name = raw_input()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send(name)
thread.start_new_thread(handle, (s,))
while 1:
msg = raw_input()
if not msg:
continue
s.send(msg)
s.close()
print '---chatting program is end---'