UnitySocketIO-WebSocketSharp
============================
[UnitySocketIO](https://github.com/NetEase/UnitySocketIO) using [websocket-sharp](https://github.com/sta/websocket-sharp) instead of [WebSocket4Net](https://github.com/kerryjiang/WebSocket4Net)
- UnitySocketIO is the only usable socket.io client for unity3d, but it's using WebSocket4Net and SuperSocket.ClientEngine as underlying libraries, which are somewhat buggy and unstable.
- There are times when the MessageReceived event handler is not called, even though the client has received a message packet from the server, and the message silently gets dropped.
- When WebSocket4Net library used by UnitySocketIO was replaced with websocket-sharp, the problem has been solved.
- [SimpleJson](https://github.com/facebook-csharp-sdk/simple-json) library used by UnitySocketIO was updated to the latest version (v0.30.0), because the old one caused crashes in some cases.
###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](https://github.com/facebook-csharp-sdk/simple-json), [websocket-sharp](https://github.com/sta/websocket-sharp), UnitySocketIO-WebSocketSharp to a folder of your project, instead of the DLLs.
- And before you build it, you have to modify WebSocket.cs of websocket-sharp as follows:
```
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;
...
}
```
- Modify Net/ListenerAsyncResult.cs of websocket-sharp as follows:
```
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);
}
```
- Uncomment "#define SIMPLE_JSON_NO_LINQ_EXPRESSION" in SimpleJson.cs.
##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.
没有合适的资源?快使用搜索试试~ 我知道了~
UnitySocketIO
共102个文件
cs:90个
dll:3个
csproj:2个
需积分: 14 10 下载量 77 浏览量
2018-09-13
15:59:23
上传
评论
收藏 340KB ZIP 举报
温馨提示
websocket插件,可以通过使用该插件实现web通信,做到unitywebgl
资源推荐
资源详情
资源评论
收起资源包目录
UnitySocketIO (102个子文件)
SimpleJson.cs 83KB
Ext.cs 56KB
WebSocket.cs 54KB
WebHeaderCollection.cs 41KB
WebSocketServiceHostManager.cs 36KB
HttpUtility.cs 31KB
WebSocketSessionManager.cs 27KB
HttpListenerResponse.cs 23KB
HttpServer.cs 21KB
WebSocketServer.cs 21KB
Client.cs 21KB
HttpListenerRequest.cs 20KB
Cookie.cs 20KB
HttpListener.cs 19KB
WsFrame.cs 18KB
CookieCollection.cs 18KB
WebSocketService.cs 16KB
HttpStatusCode.cs 12KB
EndPointListener.cs 11KB
HttpConnection.cs 11KB
Logger.cs 10KB
TcpListenerWebSocketContext.cs 10KB
HttpListenerWebSocketContext.cs 10KB
HttpListenerPrefixCollection.cs 9KB
ChunkStream.cs 8KB
AuthenticationResponse.cs 8KB
WebSocketContext.cs 7KB
ResponseStream.cs 7KB
WebSocketServiceHost.cs 7KB
RequestStream.cs 6KB
WsStream.cs 6KB
HttpListenerContext.cs 5KB
ChunkedInputStream.cs 5KB
ListenerAsyncResult.cs 5KB
ListenerPrefix.cs 5KB
HandshakeRequest.cs 5KB
EndPointManager.cs 5KB
Message.cs 5KB
CloseStatusCode.cs 5KB
AuthenticationChallenge.cs 5KB
LogData.cs 4KB
CookieException.cs 4KB
HandshakeResponse.cs 4KB
PayloadData.cs 4KB
HttpListenerException.cs 4KB
MessageEventArgs.cs 4KB
CloseEventArgs.cs 3KB
RegistrationManager.cs 3KB
WsCredential.cs 3KB
HttpRequestEventArgs.cs 3KB
HttpStreamAsyncResult.cs 3KB
HttpHeaderInfo.cs 2KB
SslStream.cs 2KB
EventMessage.cs 2KB
HandshakeBase.cs 2KB
IWebSocketSession.cs 2KB
WebSocketState.cs 2KB
WebSocketException.cs 2KB
Opcode.cs 2KB
AuthenticationSchemes.cs 2KB
AckMessage.cs 2KB
ErrorEventArgs.cs 2KB
LogLevel.cs 2KB
CompressionMethod.cs 2KB
AuthenticationSchemeSelector.cs 2KB
SocketIOHandshake.cs 2KB
JsonEncodedEventMessage.cs 2KB
HttpVersion.cs 2KB
JSONMessage.cs 2KB
ByteOrder.cs 2KB
IMessage.cs 2KB
HttpHeaderType.cs 1KB
ConnectMessage.cs 1KB
ServerState.cs 1KB
Mask.cs 1KB
Fin.cs 1KB
Rsv.cs 1KB
DisconnectMessage.cs 1KB
TextMessage.cs 1KB
EndPointClient.cs 1KB
AssemblyInfo.cs 1KB
CMain.cs 1KB
ErrorMessage.cs 1024B
IClient.cs 933B
SocketIOMessageTypes.cs 859B
NoopMessage.cs 532B
Heartbeat.cs 476B
ErrorEventArgs.cs 472B
IEndPointClient.cs 363B
MessageEventArgs.cs 331B
websocket-sharp.csproj 6KB
SocketIO.csproj 3KB
websocket-sharp.dll 197KB
SimpleJson.dll 28KB
SocketIO.dll 26KB
.gitignore 48B
README.md 4KB
SocketIO.pidb 46KB
doc.sh 622B
SocketIO.sln 863B
共 102 条
- 1
- 2
资源评论
5个小时代
- 粉丝: 0
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功