服务器端产生了一条错误信息,客户端断开服务器时,服务器端会产生一条错误信息...

我将game-server/node_modules/pomelo/node_modules/ws/lib/WebSocket.js:563:65)的代码换了个位置,

self._receiver.onerror = function(reason, errorCode) {console.assert(false);

// close the connection when the receiver reports a HyBi error code

self.close(typeof errorCode != 'undefined' ? errorCode : 1002, '');

self.emit('error', reason, errorCode);

};

如下:

self._receiver.onerror = function(reason, errorCode) {console.assert(false);

// close the connection when the receiver reports a HyBi error code

self.emit('error', reason, errorCode);

self.close(typeof errorCode != 'undefined' ? errorCode : 1002, '');

};

不知道这样改对不对,有遇到同样问题的朋友吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一段简单的TCP通讯协议,用于实现两个客户端服务器端轮流通讯: 1. 客户端连接服务器端,向服务器端发送一条消息。 2. 服务器端接收到消息后,向所有已连接的客户端发送该消息,并等待下一个客户端发送消息。 3. 下一个客户端连接服务器端,向服务器端发送一条消息。 4. 服务器端接收到消息后,向所有已连接的客户端发送该消息,并等待下一个客户端发送消息。 5. 重复步骤3-4,直到所有客户端断开连接。 以下是Python代码示例: 服务器端: ```python import socket HOST = '' # 监听所有可用的接口 PORT = 8888 # 监听指定的端口号 BUFFER_SIZE = 1024 # 创建TCP套接字 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 绑定地址和端口号 s.bind((HOST, PORT)) # 设置最大连接数 s.listen(2) print('Server is listening on port', PORT) # 等待客户端连接 conn1, addr1 = s.accept() print('Client 1 connected:', addr1) conn2, addr2 = s.accept() print('Client 2 connected:', addr2) # 向客户端1发送欢迎消息 conn1.send('Welcome to the chat room!'.encode()) while True: # 接收客户端1的消息 data = conn1.recv(BUFFER_SIZE) if data: # 将消息转发给客户端2 conn2.send(data) # 等待客户端2的消息 data = conn2.recv(BUFFER_SIZE) if data: # 将消息转发给客户端1 conn1.send(data) # 关闭连接 conn1.close() conn2.close() s.close() ``` 客户端: ```python import socket HOST = 'localhost' # 服务器的主机名或IP地址 PORT = 8888 # 服务器指定的端口号 BUFFER_SIZE = 1024 # 创建TCP套接字 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 连接服务器 s.connect((HOST, PORT)) while True: # 接收服务器的消息 data = s.recv(BUFFER_SIZE) if data: print(data.decode()) # 发送消息给服务器 message = input() s.send(message.encode()) # 关闭连接 s.close() ``` 客户端可以启动两个,分别连接到服务器端,然后轮流发送消息即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值