Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mattqs committed Sep 28, 2017
1 parent 171072e commit 3784f18
Show file tree
Hide file tree
Showing 24 changed files with 492 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
<HintPath>..\EngineIoClientDotNet.net35\packages\Newtonsoft.Json.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.12, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net35\packages\SuperSocket.ClientEngine.Core.0.8.0.12\lib\net35-client\SuperSocket.ClientEngine.dll</HintPath>
<Private>True</Private>
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.13, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net35\packages\SuperSocket.ClientEngine.Core.0.8.0.13\lib\net35-client\SuperSocket.ClientEngine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -49,8 +48,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebSocket4Net, Version=0.15.0.9, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net35\packages\WebSocket4Net.0.15.0-beta9\lib\net35\WebSocket4Net.dll</HintPath>
<Private>True</Private>
<HintPath>..\EngineIoClientDotNet.net35\packages\WebSocket4Net.0.15.0\lib\net35\WebSocket4Net.dll</HintPath>
</Reference>
<Reference Include="xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net35\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
Expand All @@ -77,6 +75,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
Expand Down
11 changes: 11 additions & 0 deletions Src/EngineIoClientDotNet.Tests.net35/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="SuperSocket.ClientEngine" publicKeyToken="ee9af13f57f00acc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.8.0.12" newVersion="0.8.0.12" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
4 changes: 2 additions & 2 deletions Src/EngineIoClientDotNet.Tests.net35/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<packages>
<package id="more.xunit.runner.visualstudio" version="2.2.2" targetFramework="net35" developmentDependency="true" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net35" />
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.12" targetFramework="net35" />
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.13" targetFramework="net35" />
<package id="System.Threading.Tasks.Unofficial" version="3.1" targetFramework="net35" />
<package id="WebSocket4Net" version="0.15.0-beta9" targetFramework="net35" />
<package id="WebSocket4Net" version="0.15.0" targetFramework="net35" />
<package id="xunit" version="1.9.2" targetFramework="net35" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
<HintPath>..\EngineIoClientDotNet.net40\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.12, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net40\packages\SuperSocket.ClientEngine.Core.0.8.0.12\lib\net45\SuperSocket.ClientEngine.dll</HintPath>
<Private>True</Private>
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.13, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net40\packages\SuperSocket.ClientEngine.Core.0.8.0.13\lib\net45\SuperSocket.ClientEngine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -52,8 +51,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebSocket4Net, Version=0.15.0.9, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net40\packages\WebSocket4Net.0.15.0-beta9\lib\net45\WebSocket4Net.dll</HintPath>
<Private>True</Private>
<HintPath>..\EngineIoClientDotNet.net40\packages\WebSocket4Net.0.15.0\lib\net45\WebSocket4Net.dll</HintPath>
</Reference>
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net40\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
Expand Down Expand Up @@ -128,6 +126,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
11 changes: 11 additions & 0 deletions Src/EngineIoClientDotNet.Tests.net40/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="SuperSocket.ClientEngine" publicKeyToken="ee9af13f57f00acc" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.8.0.12" newVersion="0.8.0.12" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
4 changes: 2 additions & 2 deletions Src/EngineIoClientDotNet.Tests.net40/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.12" targetFramework="net452" />
<package id="WebSocket4Net" version="0.15.0-beta9" targetFramework="net452" />
<package id="SuperSocket.ClientEngine.Core" version="0.8.0.13" targetFramework="net452" />
<package id="WebSocket4Net" version="0.15.0" targetFramework="net452" />
<package id="xunit" version="2.3.0-beta3-build3705" targetFramework="net452" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" />
<package id="xunit.analyzers" version="0.3.0" targetFramework="net452" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<HintPath>..\EngineIoClientDotNet.net45\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net45\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
<Reference Include="System.Collections.Immutable, Version=1.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\EngineIoClientDotNet.net45\packages\System.Collections.Immutable.1.4.0\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion Src/EngineIoClientDotNet.Tests.net45/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="System.Collections" version="4.3.0" targetFramework="net45" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net45" />
<package id="System.Collections.Immutable" version="1.3.1" targetFramework="net45" />
<package id="System.Collections.Immutable" version="1.4.0" targetFramework="net45" />
<package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net45" />
<package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net45" />
<package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net45" />
Expand Down
8 changes: 2 additions & 6 deletions Src/EngineIoClientDotNet.mono/Client/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Quobject.EngineIoClientDotNet.Thread;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;


Expand Down Expand Up @@ -671,12 +672,7 @@ private Task WaitForUpgrade()
{
log.Info("Wait for upgrade timeout");
break;
}
else
{
// yield to another thread
System.Threading.Thread.Yield();
}
}
}
tcs.SetResult(null);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
using Quobject.EngineIoClientDotNet.Modules;
using Quobject.EngineIoClientDotNet.Parser;
using System;
using System.Net;
using System.Collections.Generic;
using WebSocket4Net;
using SuperSocket.ClientEngine.Proxy;

namespace Quobject.EngineIoClientDotNet.Client.Transports
{
public class WebSocket : Transport
{
public static readonly string NAME = "websocket";

private WebSocket4Net.WebSocket ws;
private List<KeyValuePair<string, string>> Cookies;
private List<KeyValuePair<string, string>> MyExtraHeaders;

public WebSocket(Options opts)
: base(opts)
{
Name = NAME;
Cookies = new List<KeyValuePair<string, string>>();
foreach (var cookie in opts.Cookies)
{
Cookies.Add(new KeyValuePair<string, string>(cookie.Key, cookie.Value));
}
MyExtraHeaders = new List<KeyValuePair<string, string>>();
foreach (var header in opts.ExtraHeaders)
{
MyExtraHeaders.Add(new KeyValuePair<string, string>(header.Key, header.Value));
}
}

protected override void DoOpen()
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("DoOpen uri =" + this.Uri());

ws = new WebSocket4Net.WebSocket(this.Uri(), String.Empty, Cookies, MyExtraHeaders)
{
EnableAutoSendPing = false
};
if (ServerCertificate.Ignore)
{
var security = ws.Security;

if (security != null)
{
security.AllowUnstrustedCertificate = true;
security.AllowNameMismatchCertificate = true;
}
}
ws.Opened += ws_Opened;
ws.Closed += ws_Closed;
ws.MessageReceived += ws_MessageReceived;
ws.DataReceived += ws_DataReceived;
ws.Error += ws_Error;

var destUrl = new UriBuilder(this.Uri());
if (this.Secure)
destUrl.Scheme = "https";
else
destUrl.Scheme = "http";
var useProxy = !WebRequest.DefaultWebProxy.IsBypassed(destUrl.Uri);
if (useProxy)
{
var proxyUrl = WebRequest.DefaultWebProxy.GetProxy(destUrl.Uri);
var proxy = new HttpConnectProxy(new DnsEndPoint(proxyUrl.Host, proxyUrl.Port), destUrl.Host);
ws.Proxy = proxy;
}
ws.Open();
}

void ws_DataReceived(object sender, DataReceivedEventArgs e)
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("ws_DataReceived " + e.Data);
this.OnData(e.Data);
}

private void ws_Opened(object sender, EventArgs e)
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("ws_Opened " + ws.SupportBinary);
this.OnOpen();
}

void ws_Closed(object sender, EventArgs e)
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("ws_Closed");
ws.Opened -= ws_Opened;
ws.Closed -= ws_Closed;
ws.MessageReceived -= ws_MessageReceived;
ws.DataReceived -= ws_DataReceived;
ws.Error -= ws_Error;
this.OnClose();
}

void ws_MessageReceived(object sender, MessageReceivedEventArgs e)
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("ws_MessageReceived e.Message= " + e.Message);
this.OnData(e.Message);
}

void ws_Error(object sender, SuperSocket.ClientEngine.ErrorEventArgs e)
{
this.OnError("websocket error", e.Exception);
}

protected override void Write(System.Collections.Immutable.ImmutableList<Parser.Packet> packets)
{
Writable = false;
foreach (var packet in packets)
{
Parser.Parser.EncodePacket(packet, new WriteEncodeCallback(this));
}

// fake drain
// defer to next tick to allow Socket to clear writeBuffer
//EasyTimer.SetTimeout(() =>
//{
Writable = true;
Emit(EVENT_DRAIN);
//}, 1);
}

public class WriteEncodeCallback : IEncodeCallback
{
private WebSocket webSocket;

public WriteEncodeCallback(WebSocket webSocket)
{
this.webSocket = webSocket;
}

public void Call(object data)
{
//var log = LogManager.GetLogger(Global.CallerName());

if (data is string)
{
webSocket.ws.Send((string)data);
}
else if (data is byte[])
{
var d = (byte[])data;

//try
//{
// var dataString = BitConverter.ToString(d);
// //log.Info(string.Format("WriteEncodeCallback byte[] data {0}", dataString));
//}
//catch (Exception e)
//{
// log.Error(e);
//}

webSocket.ws.Send(d, 0, d.Length);
}
}
}



protected override void DoClose()
{
if (ws != null)
{

try
{
ws.Close();
}
catch (Exception e)
{
var log = LogManager.GetLogger(Global.CallerName());
log.Info("DoClose ws.Close() Exception= " + e.Message);
}
}
}



public string Uri()
{
Dictionary<string, string> query = null;
query = this.Query == null ? new Dictionary<string, string>() : new Dictionary<string, string>(this.Query);
var schema = this.Secure ? "wss" : "ws";
var portString = "";

if (this.TimestampRequests)
{
query.Add(this.TimestampParam, DateTime.Now.Ticks.ToString() + "-" + Transport.Timestamps++);
}

var _query = ParseQS.Encode(query);

if (this.Port > 0 && (("wss" == schema && this.Port != 443)
|| ("ws" == schema && this.Port != 80)))
{
portString = ":" + this.Port;
}

if (_query.Length > 0)
{
_query = "?" + _query;
}

return schema + "://" + this.Hostname + portString + this.Path + _query;
}
}
}
2 changes: 1 addition & 1 deletion Src/EngineIoClientDotNet.mono/Parser/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static void DecodePayload(string data, IDecodePayloadCallback callback)

if (msg.Length != 0)
{
Packet packet = DecodePacket(msg, false);
Packet packet = DecodePacket(msg, true);
if (_err.Type == packet.Type && _err.Data == packet.Data)
{
callback.Call(_err, 0, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.12, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
<HintPath>packages\SuperSocket.ClientEngine.Core.0.8.0.12\lib\net35-client\SuperSocket.ClientEngine.dll</HintPath>
<Private>True</Private>
<Reference Include="SuperSocket.ClientEngine, Version=0.8.0.13, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
<HintPath>packages\SuperSocket.ClientEngine.Core.0.8.0.13\lib\net35-client\SuperSocket.ClientEngine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -50,8 +49,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebSocket4Net, Version=0.15.0.9, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
<HintPath>packages\WebSocket4Net.0.15.0-beta9\lib\net35\WebSocket4Net.dll</HintPath>
<Private>True</Private>
<HintPath>packages\WebSocket4Net.0.15.0\lib\net35\WebSocket4Net.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
Loading

0 comments on commit 3784f18

Please sign in to comment.