Home

Awesome

UnitySocketIO-WebSocketSharp

UnitySocketIO using websocket-sharp instead of WebSocket4Net

How to use

Copy all the DLLs from /SocketIO/bin/Debug/ to any folder of your project (e.g. Assets/Plugins/SocketIO/)

Avoiding too long wait on Close event

websocket-sharp uses AutoResetEvent.WaitOne on Close event, but it looks like socket.io server doesn't return Close frame and the client must wait until the timeout (5 seconds) expires.

If you add just one line below in the method "private bool close (byte [] frameAsBytes, int timeOut, Func<bool> release)" of "websocket-sharp/WebSocket.cs" file, it'll be solved.

private bool close (byte [] frameAsBytes, int timeOut, Func<bool> release)
{
  timeOut = 0; // no closing handshake
  
  var sent = frameAsBytes != null && _stream.Write (frameAsBytes);
  ...

Building for iOS devices

If you want to build this library for iOS devices, you have to copy all the sources of SimpleJson, websocket-sharp, UnitySocketIO-WebSocketSharp to a folder of your project, instead of the DLLs.

internal delegate bool SendBytesFunc (Opcode opcode, byte [] data);
internal delegate bool SendStreamFunc (Opcode opcode, Stream stream);

private void send (Opcode opcode, byte [] data, Action<bool> completed)
{
  //Func<Opcode, byte [], bool> sender = send;
  SendBytesFunc sender = send;
  ...
}

private void send (Opcode opcode, Stream stream, Action<bool> completed)
{
  //Func<Opcode, Stream, bool> sender = send;
  SendStreamFunc sender = send;
  ...
}
internal void Complete (Exception exc)
{
  ...
  //ThreadPool.UnsafeQueueUserWorkItem (InvokeCB, this);
  ThreadPool.QueueUserWorkItem (InvokeCB, this);
}

...

internal void Complete (HttpListenerContext context, bool synch)
{
  ...
  //ThreadPool.UnsafeQueueUserWorkItem (InvokeCB, this);
  ThreadPool.QueueUserWorkItem (InvokeCB, this);
}

License

(The MIT License)

Copyright (c) 2014 kaistseo and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.