24 lines
667 B
Python
24 lines
667 B
Python
|
|
import configparser
|
||
|
|
config = configparser.ConfigParser()
|
||
|
|
config.read('controlled.ini')
|
||
|
|
listen_ip = config.get('connection', 'listen_ip')
|
||
|
|
listen_port = int(config.get('connection', 'listen_port'))
|
||
|
|
|
||
|
|
import socket
|
||
|
|
|
||
|
|
# 创建一个TCP套接字
|
||
|
|
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||
|
|
|
||
|
|
# 连接到服务器
|
||
|
|
client_socket.connect((listen_ip, listen_port))
|
||
|
|
|
||
|
|
# 发送数据
|
||
|
|
message = 'Hello, server!' # 这里可以替换为你想要发送的数据
|
||
|
|
client_socket.sendall(message.encode())
|
||
|
|
|
||
|
|
# 接收服务器的响应
|
||
|
|
response = client_socket.recv(1024)
|
||
|
|
print(f'从服务器接收响应: {response.decode()}')
|
||
|
|
|
||
|
|
# 关闭套接字
|
||
|
|
client_socket.close()
|