tl;博士从 PC 和移远 GPRS 模块发送相同的数据从移远通信发送时,服务器引发异常 Connection reset by peer但是移远通信在具有相同 EC2-micro 实例和负载均衡器的生产环境中工作。除了 Quectel,另一个 GPRS 模块 - Neoway M680 - 与这个 EC2 实例一起工作。设置本地 - 设置我有一个 Quectel M66,一个 GPRS 模块,我用来连接到服务器 ( AWS EC2 ) 并传输一些数据。我也有一个python script我已经使用 PC 连接和发送相同的数据。下面是python脚本import socketimport sysfrom io import openfrom time import sleep'''Python script to send data to remote server'''#replace address with the remote server addressHOST, PORT = '127.0.0.1', 3000 if len(sys.argv) < 2: error = "Error:" print("{} {}".format(error, "Pass in the file to be send")) exit(1)filename = sys.argv[1]with open(filename, "r", newline="\r") as f: lines = f.readlines()data = "".join(lines)# Create a socket (SOCK_STREAM means a TCP socket)with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: # Connect to server and send data sock.connect((HOST, PORT)) sock.sendall(bytes(data, "utf-8")) # Receive data from the server and shut down received = r"{}".format(sock.recv(1024)) sock.close()print("Received: {}".format(received))远程 - 设置我正在运行一个EC2-micro实例,该实例运行一个 python 脚本,它只监听一个端口并打印它接收到的数据,还发送一个硬编码的响应。这是脚本#!/usr/bin/env python3'''Python code running on EC2-micro'''import socketimport errnofrom datetime import datetimeprint(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))HOST = '0.0.0.0' # Standard loopback interface address (localhost)PORT = 3000 # Port to listen on (non-privileged ports are > 1023)with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((HOST, PORT)) s.listen() conn, addr = s.accept() with conn: print('Connected by', addr)
添加回答
举报
0/150
提交
取消