@@ -9,8 +9,9 @@ namespace SocketIOClient.Transport
99{
1010 public class WebSocketTransport : IReceivable , IDisposable
1111 {
12- public WebSocketTransport ( IClientWebSocket ws )
12+ public WebSocketTransport ( IClientWebSocket ws , int eio )
1313 {
14+ _eio = eio ;
1415 _ws = ws ;
1516 ReceiveChunkSize = 1024 * 8 ;
1617 SendChunkSize = 1024 * 8 ;
@@ -27,6 +28,7 @@ public WebSocketTransport(IClientWebSocket ws)
2728 public Action < byte [ ] > OnBinaryReceived { get ; set ; }
2829 public Action < Exception > OnAborted { get ; set ; }
2930
31+ readonly int _eio ;
3032 readonly IClientWebSocket _ws ;
3133 readonly CancellationTokenSource _listenCancellation ;
3234
@@ -53,7 +55,17 @@ public async Task DisconnectAsync(CancellationToken cancellationToken)
5355 /// <exception cref="TaskCanceledException"></exception>
5456 public async Task SendAsync ( byte [ ] bytes , CancellationToken cancellationToken )
5557 {
56- await SendAsync ( WebSocketMessageType . Binary , bytes , cancellationToken ) ;
58+ if ( _eio == 3 )
59+ {
60+ byte [ ] buffer = new byte [ bytes . Length + 1 ] ;
61+ buffer [ 0 ] = 4 ;
62+ Buffer . BlockCopy ( bytes , 0 , buffer , 1 , bytes . Length ) ;
63+ await SendAsync ( WebSocketMessageType . Binary , buffer , cancellationToken ) ;
64+ }
65+ else
66+ {
67+ await SendAsync ( WebSocketMessageType . Binary , bytes , cancellationToken ) ;
68+ }
5769 }
5870
5971 private async Task SendAsync ( WebSocketMessageType type , byte [ ] bytes , CancellationToken cancellationToken )
@@ -135,8 +147,17 @@ private async Task ListenAsync()
135147 OnTextReceived ( text ) ;
136148 break ;
137149 case WebSocketMessageType . Binary :
138- byte [ ] bytes = new byte [ count ] ;
139- Buffer . BlockCopy ( buffer , 0 , bytes , 0 , bytes . Length ) ;
150+ byte [ ] bytes ;
151+ if ( _eio == 3 )
152+ {
153+ bytes = new byte [ count - 1 ] ;
154+ Buffer . BlockCopy ( buffer , 1 , bytes , 0 , bytes . Length ) ;
155+ }
156+ else
157+ {
158+ bytes = new byte [ count ] ;
159+ Buffer . BlockCopy ( buffer , 0 , bytes , 0 , bytes . Length ) ;
160+ }
140161 OnBinaryReceived ( bytes ) ;
141162 break ;
142163 case WebSocketMessageType . Close :
0 commit comments