0
私のコードであなたの助けが必要です。私は自分のraspiカメラMJPG-Streamを実行するクライアント+サーバを構築しています。Regex - サーバーに不要な文字を無視する方法
import socket
import subprocess
import re
comms_socket = socket.socket()
comms_socket.bind(('', 4244))
comms_socket.listen(20)
reg_vyraz = "Start(\d+)x(\d+)x(\d+)"
try:
while True:
print("Waiting for connection... (Ctrl+C to exit)")
connection, adress = comms_socket.accept()
print("Connected")
try:
while True:
received = connection.recv(4096).decode('UTF-8')
if (len(received) == 0):
break;
m = re.match(reg_vyraz, received)
hodnoty = m.groups()
for cislo in hodnoty:
print (cislo)
print ('Received ', hodnoty, ' from the client')
sys.stdout.write("\n")
except KeyboardInterrupt:
print("Closing connection")
connection.close()
except KeyboardInterrupt:
print("Closing server")
comms_socket.close()
何をしていますか?クライアントがサーバに送信するとき:Start640x450x20、サーバーは、とのストリームを実行します: 幅-640 身長-450 FPS-20
私に必要なのは、私はには、この「Start640x450x20」を入れたときにのみ、これを実行するために、ありますクライアント、私は "gfjlshgslsd"のようなものを書くときに、私はそれを無視するために、サーバーがダウンしないようにする必要があります。
ありがとうございました。
感謝を呼び出す前に、私はそれを試してみましたが、私は「OK」のようなクライアント何かに入れたときに、それはまだ最も最近の(私のトレースバックを与えない場合にだけチェック)最後の呼び出し: 'NoneType' オブジェクトが無属性のグループの – Ryci
2つの質問があります:ポストで 1.を、 hodnoty = m.groups() はAttributeErrorで ファイル "stream.py"、ライン28を、内側のブロックのインデントは間違っています。 2.あなたは** print( 'Received'、hodnoty、 'from client')**を入れてください。 –
ああ、私の悪い@Dhruv Aggarwal。助けてくれてありがとうございます。 – Ryci