websocket服务器响应头,从服务器发送响应握手后,websocket.onopen不会触发

本文档描述了一个WebSocket服务器实现的问题,即在正确发送响应握手后,`websocket.onopen`事件未触发。代码示例展示了服务器如何接收客户端连接,处理WebSocket握手,并发送服务器响应。然而,当服务器读取网络流时,`onopen`事件没有如预期般激活,而是在服务器关闭时触发了`onclose`事件。问题可能与服务器保持活动状态的机制有关。
摘要由CSDN通过智能技术生成

下面我已详细分享了我的代码。我阅读文档和关于握手的一切。我遵循了文档中提供的所有步骤以及互联网上的众多示例,但仍然存在此问题。奇怪的事情id websocket.onclsose()在我关闭服务器时被触发。从服务器发送响应握手后,websocket.onopen不会触发

// Simple Websocket server

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Net.Sockets;

using System.Net;

using System.IO;

using System.Security.Cryptography;

using System.Threading;

namespace WebSocketServer

{

class Program

{

//port

private static int _port = 8181;

static void Main(string[] args)

{

TcpListener t = new TcpListener(IPAddress.Loopback, _port);

t.Start();

Console.WriteLine("Server is started and waiting for client\n\n");

byte[] buff = new byte[255];

NetworkStream stream;

TcpClient clie

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值