Skip to content

Commit 3784f18

Browse files
committed
1.0.3
1 parent 171072e commit 3784f18

24 files changed

Lines changed: 492 additions & 66 deletions

File tree

Src/EngineIoClientDotNet.Tests.net35/EngineIoClientDotNet.Tests.net35.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
<HintPath>..\EngineIoClientDotNet.net35\packages\Newtonsoft.Json.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
3535
<Private>True</Private>
3636
</Reference>
37-
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.12, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
38-
<HintPath>..\EngineIoClientDotNet.net35\packages\SuperSocket.ClientEngine.Core.0.8.0.12\lib\net35-client\SuperSocket.ClientEngine.dll</HintPath>
39-
<Private>True</Private>
37+
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.13, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
38+
<HintPath>..\EngineIoClientDotNet.net35\packages\SuperSocket.ClientEngine.Core.0.8.0.13\lib\net35-client\SuperSocket.ClientEngine.dll</HintPath>
4039
</Reference>
4140
<Reference Include="System" />
4241
<Reference Include="System.Core" />
@@ -49,8 +48,7 @@
4948
<Reference Include="System.Data" />
5049
<Reference Include="System.Xml" />
5150
<Reference Include="WebSocket4Net, Version=0.15.0.9, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
52-
<HintPath>..\EngineIoClientDotNet.net35\packages\WebSocket4Net.0.15.0-beta9\lib\net35\WebSocket4Net.dll</HintPath>
53-
<Private>True</Private>
51+
<HintPath>..\EngineIoClientDotNet.net35\packages\WebSocket4Net.0.15.0\lib\net35\WebSocket4Net.dll</HintPath>
5452
</Reference>
5553
<Reference Include="xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
5654
<HintPath>..\EngineIoClientDotNet.net35\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
@@ -77,6 +75,7 @@
7775
<Compile Include="Properties\AssemblyInfo.cs" />
7876
</ItemGroup>
7977
<ItemGroup>
78+
<None Include="app.config" />
8079
<None Include="packages.config" />
8180
</ItemGroup>
8281
<ItemGroup />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="SuperSocket.ClientEngine" publicKeyToken="ee9af13f57f00acc" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-0.8.0.12" newVersion="0.8.0.12" />
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>

Src/EngineIoClientDotNet.Tests.net35/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<packages>
33
<package id="more.xunit.runner.visualstudio" version="2.2.2" targetFramework="net35" developmentDependency="true" />
44
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net35" />
5-
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.12" targetFramework="net35" />
5+
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.13" targetFramework="net35" />
66
<package id="System.Threading.Tasks.Unofficial" version="3.1" targetFramework="net35" />
7-
<package id="WebSocket4Net" version="0.15.0-beta9" targetFramework="net35" />
7+
<package id="WebSocket4Net" version="0.15.0" targetFramework="net35" />
88
<package id="xunit" version="1.9.2" targetFramework="net35" />
99
</packages>

Src/EngineIoClientDotNet.Tests.net40/EngineIoClientDotNet.Tests.net40.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@
4040
<HintPath>..\EngineIoClientDotNet.net40\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
4141
<Private>True</Private>
4242
</Reference>
43-
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.12, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
44-
<HintPath>..\EngineIoClientDotNet.net40\packages\SuperSocket.ClientEngine.Core.0.8.0.12\lib\net45\SuperSocket.ClientEngine.dll</HintPath>
45-
<Private>True</Private>
43+
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.13, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
44+
<HintPath>..\EngineIoClientDotNet.net40\packages\SuperSocket.ClientEngine.Core.0.8.0.13\lib\net45\SuperSocket.ClientEngine.dll</HintPath>
4645
</Reference>
4746
<Reference Include="System" />
4847
<Reference Include="System.Core" />
@@ -52,8 +51,7 @@
5251
<Reference Include="System.Data" />
5352
<Reference Include="System.Xml" />
5453
<Reference Include="WebSocket4Net, Version=0.15.0.9, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
55-
<HintPath>..\EngineIoClientDotNet.net40\packages\WebSocket4Net.0.15.0-beta9\lib\net45\WebSocket4Net.dll</HintPath>
56-
<Private>True</Private>
54+
<HintPath>..\EngineIoClientDotNet.net40\packages\WebSocket4Net.0.15.0\lib\net45\WebSocket4Net.dll</HintPath>
5755
</Reference>
5856
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
5957
<HintPath>..\EngineIoClientDotNet.net40\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
@@ -128,6 +126,7 @@
128126
</ProjectReference>
129127
</ItemGroup>
130128
<ItemGroup>
129+
<None Include="app.config" />
131130
<None Include="config.json">
132131
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
133132
</None>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="SuperSocket.ClientEngine" publicKeyToken="ee9af13f57f00acc" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-0.8.0.12" newVersion="0.8.0.12" />
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>

Src/EngineIoClientDotNet.Tests.net40/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
4-
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.12" targetFramework="net452" />
5-
<package id="WebSocket4Net" version="0.15.0-beta9" targetFramework="net452" />
4+
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.13" targetFramework="net452" />
5+
<package id="WebSocket4Net" version="0.15.0" targetFramework="net452" />
66
<package id="xunit" version="2.3.0-beta3-build3705" targetFramework="net452" />
77
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
88
<package id="xunit.analyzers" version="0.3.0" targetFramework="net452" />

Src/EngineIoClientDotNet.Tests.net45/EngineIoClientDotNet.Tests.net45.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
<HintPath>..\EngineIoClientDotNet.net45\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
3939
</Reference>
4040
<Reference Include="System" />
41-
<Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
42-
<HintPath>..\EngineIoClientDotNet.net45\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
41+
<Reference Include="System.Collections.Immutable, Version=1.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
42+
<HintPath>..\EngineIoClientDotNet.net45\packages\System.Collections.Immutable.1.4.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
4343
</Reference>
4444
<Reference Include="System.ComponentModel.Composition" />
4545
<Reference Include="System.Core" />

Src/EngineIoClientDotNet.Tests.net45/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
66
<package id="System.Collections" version="4.3.0" targetFramework="net45" />
77
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net45" />
8-
<package id="System.Collections.Immutable" version="1.3.1" targetFramework="net45" />
8+
<package id="System.Collections.Immutable" version="1.4.0" targetFramework="net45" />
99
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net45" />
1010
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net45" />
1111
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net45" />

Src/EngineIoClientDotNet.mono/Client/Socket.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Quobject.EngineIoClientDotNet.Thread;
88
using System;
99
using System.Collections.Generic;
10+
using System.Threading;
1011
using System.Threading.Tasks;
1112

1213

@@ -671,12 +672,7 @@ private Task WaitForUpgrade()
671672
{
672673
log.Info("Wait for upgrade timeout");
673674
break;
674-
}
675-
else
676-
{
677-
// yield to another thread
678-
System.Threading.Thread.Yield();
679-
}
675+
}
680676
}
681677
tcs.SetResult(null);
682678
}
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
using Quobject.EngineIoClientDotNet.Modules;
2+
using Quobject.EngineIoClientDotNet.Parser;
3+
using System;
4+
using System.Net;
5+
using System.Collections.Generic;
6+
using WebSocket4Net;
7+
using SuperSocket.ClientEngine.Proxy;
8+
9+
namespace Quobject.EngineIoClientDotNet.Client.Transports
10+
{
11+
public class WebSocket : Transport
12+
{
13+
public static readonly string NAME = "websocket";
14+
15+
private WebSocket4Net.WebSocket ws;
16+
private List<KeyValuePair<string, string>> Cookies;
17+
private List<KeyValuePair<string, string>> MyExtraHeaders;
18+
19+
public WebSocket(Options opts)
20+
: base(opts)
21+
{
22+
Name = NAME;
23+
Cookies = new List<KeyValuePair<string, string>>();
24+
foreach (var cookie in opts.Cookies)
25+
{
26+
Cookies.Add(new KeyValuePair<string, string>(cookie.Key, cookie.Value));
27+
}
28+
MyExtraHeaders = new List<KeyValuePair<string, string>>();
29+
foreach (var header in opts.ExtraHeaders)
30+
{
31+
MyExtraHeaders.Add(new KeyValuePair<string, string>(header.Key, header.Value));
32+
}
33+
}
34+
35+
protected override void DoOpen()
36+
{
37+
var log = LogManager.GetLogger(Global.CallerName());
38+
log.Info("DoOpen uri =" + this.Uri());
39+
40+
ws = new WebSocket4Net.WebSocket(this.Uri(), String.Empty, Cookies, MyExtraHeaders)
41+
{
42+
EnableAutoSendPing = false
43+
};
44+
if (ServerCertificate.Ignore)
45+
{
46+
var security = ws.Security;
47+
48+
if (security != null)
49+
{
50+
security.AllowUnstrustedCertificate = true;
51+
security.AllowNameMismatchCertificate = true;
52+
}
53+
}
54+
ws.Opened += ws_Opened;
55+
ws.Closed += ws_Closed;
56+
ws.MessageReceived += ws_MessageReceived;
57+
ws.DataReceived += ws_DataReceived;
58+
ws.Error += ws_Error;
59+
60+
var destUrl = new UriBuilder(this.Uri());
61+
if (this.Secure)
62+
destUrl.Scheme = "https";
63+
else
64+
destUrl.Scheme = "http";
65+
var useProxy = !WebRequest.DefaultWebProxy.IsBypassed(destUrl.Uri);
66+
if (useProxy)
67+
{
68+
var proxyUrl = WebRequest.DefaultWebProxy.GetProxy(destUrl.Uri);
69+
var proxy = new HttpConnectProxy(new DnsEndPoint(proxyUrl.Host, proxyUrl.Port), destUrl.Host);
70+
ws.Proxy = proxy;
71+
}
72+
ws.Open();
73+
}
74+
75+
void ws_DataReceived(object sender, DataReceivedEventArgs e)
76+
{
77+
var log = LogManager.GetLogger(Global.CallerName());
78+
log.Info("ws_DataReceived " + e.Data);
79+
this.OnData(e.Data);
80+
}
81+
82+
private void ws_Opened(object sender, EventArgs e)
83+
{
84+
var log = LogManager.GetLogger(Global.CallerName());
85+
log.Info("ws_Opened " + ws.SupportBinary);
86+
this.OnOpen();
87+
}
88+
89+
void ws_Closed(object sender, EventArgs e)
90+
{
91+
var log = LogManager.GetLogger(Global.CallerName());
92+
log.Info("ws_Closed");
93+
ws.Opened -= ws_Opened;
94+
ws.Closed -= ws_Closed;
95+
ws.MessageReceived -= ws_MessageReceived;
96+
ws.DataReceived -= ws_DataReceived;
97+
ws.Error -= ws_Error;
98+
this.OnClose();
99+
}
100+
101+
void ws_MessageReceived(object sender, MessageReceivedEventArgs e)
102+
{
103+
var log = LogManager.GetLogger(Global.CallerName());
104+
log.Info("ws_MessageReceived e.Message= " + e.Message);
105+
this.OnData(e.Message);
106+
}
107+
108+
void ws_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
109+
{
110+
this.OnError("websocket error", e.Exception);
111+
}
112+
113+
protected override void Write(System.Collections.Immutable.ImmutableList<Parser.Packet> packets)
114+
{
115+
Writable = false;
116+
foreach (var packet in packets)
117+
{
118+
Parser.Parser.EncodePacket(packet, new WriteEncodeCallback(this));
119+
}
120+
121+
// fake drain
122+
// defer to next tick to allow Socket to clear writeBuffer
123+
//EasyTimer.SetTimeout(() =>
124+
//{
125+
Writable = true;
126+
Emit(EVENT_DRAIN);
127+
//}, 1);
128+
}
129+
130+
public class WriteEncodeCallback : IEncodeCallback
131+
{
132+
private WebSocket webSocket;
133+
134+
public WriteEncodeCallback(WebSocket webSocket)
135+
{
136+
this.webSocket = webSocket;
137+
}
138+
139+
public void Call(object data)
140+
{
141+
//var log = LogManager.GetLogger(Global.CallerName());
142+
143+
if (data is string)
144+
{
145+
webSocket.ws.Send((string)data);
146+
}
147+
else if (data is byte[])
148+
{
149+
var d = (byte[])data;
150+
151+
//try
152+
//{
153+
// var dataString = BitConverter.ToString(d);
154+
// //log.Info(string.Format("WriteEncodeCallback byte[] data {0}", dataString));
155+
//}
156+
//catch (Exception e)
157+
//{
158+
// log.Error(e);
159+
//}
160+
161+
webSocket.ws.Send(d, 0, d.Length);
162+
}
163+
}
164+
}
165+
166+
167+
168+
protected override void DoClose()
169+
{
170+
if (ws != null)
171+
{
172+
173+
try
174+
{
175+
ws.Close();
176+
}
177+
catch (Exception e)
178+
{
179+
var log = LogManager.GetLogger(Global.CallerName());
180+
log.Info("DoClose ws.Close() Exception= " + e.Message);
181+
}
182+
}
183+
}
184+
185+
186+
187+
public string Uri()
188+
{
189+
Dictionary<string, string> query = null;
190+
query = this.Query == null ? new Dictionary<string, string>() : new Dictionary<string, string>(this.Query);
191+
var schema = this.Secure ? "wss" : "ws";
192+
var portString = "";
193+
194+
if (this.TimestampRequests)
195+
{
196+
query.Add(this.TimestampParam, DateTime.Now.Ticks.ToString() + "-" + Transport.Timestamps++);
197+
}
198+
199+
var _query = ParseQS.Encode(query);
200+
201+
if (this.Port > 0 && (("wss" == schema && this.Port != 443)
202+
|| ("ws" == schema && this.Port != 80)))
203+
{
204+
portString = ":" + this.Port;
205+
}
206+
207+
if (_query.Length > 0)
208+
{
209+
_query = "?" + _query;
210+
}
211+
212+
return schema + "://" + this.Hostname + portString + this.Path + _query;
213+
}
214+
}
215+
}

0 commit comments

Comments
 (0)