sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.74k stars 1.66k forks source link

immediate disconnect in WebPlayer #118

Open egradman opened 9 years ago

egradman commented 9 years ago

I'm able to connect to a websocket server with this plugin. Inside the OnOpen callback, I send a message, and it's received by the server. ,

Here's a minimal test-case:

using System;
using UnityEngine;
using System.Collections;
using WebSocketSharp;
using WebSocketSharp.Net;

public class wstest : MonoBehaviour {

  string address  = "ws://192.168.1.223:9000/";
  WebSocket webSocket;

  void Start () {
    Debug.Log("starting " + address);
    Security.PrefetchSocketPolicy("192.168.1.223", 843, 3000);

    webSocket = new WebSocket(address);
    webSocket.OnOpen += OnOpen;
    webSocket.OnMessage += OnMessageReceived;
    webSocket.OnClose += OnClose;
    webSocket.OnError += OnError;
    webSocket.Connect();
  }

  // Update is called once per frame
  void Update () {
  }

  void OnOpen(object sender, System.EventArgs e) {
    webSocket.Send("hello");
  }

  void OnMessageReceived(object sender, MessageEventArgs e)
  {
  }

  void OnClose(object sender, CloseEventArgs e)
  {
  }

  void OnError(object sender, ErrorEventArgs e)
  {
  }
}
egradman commented 9 years ago

My OnClose handler is being called. Here's a stacktrace:

websocket closed  wstest:OnClose(Object, CloseEventArgs)
WebSocketSharp.Ext:Emit(EventHandler`1, Object, CloseEventArgs)
WebSocketSharp.WebSocket:close(PayloadData, Boolean, Boolean)
WebSocketSharp.WebSocket:processCloseFrame(WsFrame)
WebSocketSharp.WebSocket:processFrame(WsFrame)
WebSocketSharp.<>c__DisplayClass11:<startReceiving>b__10(WsFrame)
WebSocketSharp.<>c__DisplayClasse:<ParseAsync>b__d(IAsyncResult)
System.Net.Sockets.SocketAsyncResult:Complete()
System.Net.Sockets.Worker:Receive()