-1
これは、localhostで実行され、ポート4160をリッスンする単純なTCPサーバーです。ただし、コードを実行すると問題が発生します。現れるエラーがあるTCPサーバーを作成するときの問題
import socket
import threading
bind_ip = "127.0.0.1"
bind_port = 4160
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((bind_ip,bind_port))
server.listen(5)
print('[*] Listening on %s:%d'% (bind_ip,bind_port))
def handle_client(client_socket):
request = client_socket.recv(1024)
print('[*] Received: %s' % request)
message = "ACK"
client_socket.sendto(message.encode('utf-8'),bind_ip,4160)
client_socket.close()
while True:
client,addr = server.accept()
print('[*] Accepted connection from: %s:%d' % (addr[0],addr[1]))
client_handler = threading.Thread(target=handle_client,args=(client,))
client_handler.start()
:
私が使用するサーバーのコードがある
[*] Listening on 127.0.0.1:24166
[*] Accepted connection from: 127.0.0.1:57455
[*] Received: b'POST /key/1/health HTTP/1.1\r\nHost: localhost:4160\r\n.....
Exception in thread Thread-12:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python35-32\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "C:\Program Files (x86)\Python35-32\lib\threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "F:/Project Folders/EthicalHacking/Server.py", line 20, in handle_client
client_socket.sendto(message.encode('utf-8'),bind_ip,4160)
TypeError: an integer is required (got type str)
この上の任意のヘルプは大歓迎されます。
send_toのAPIドキュメントを検索し、引数はデータ、IP、ポートが、データ、フラグ、アドレスではありません。 flagsはintです。とにかくそのバージョンを使用する必要はないかもしれません。 – pvg
このclient_socket.sendtoを試してみてください。 – Wonka