-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started work on a native jSock client for C#
- Loading branch information
1 parent
8e0996a
commit 807f991
Showing
105 changed files
with
754 additions
and
19 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration>Release</Configuration> | ||
<Platform>Any CPU</Platform> | ||
<PublishDir>bin\Release\net6.0\publish\</PublishDir> | ||
<PublishProtocol>FileSystem</PublishProtocol> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<SelfContained>false</SelfContained> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
https://go.microsoft.com/fwlink/?LinkID=208121. | ||
--> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<History>False|2022-02-03T11:27:05.6394928Z;</History> | ||
</PropertyGroup> | ||
</Project> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Jack Kimmins | ||
|
||
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. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"runtimeTarget": { | ||
"name": ".NETCoreApp,Version=v6.0", | ||
"signature": "" | ||
}, | ||
"compilationOptions": {}, | ||
"targets": { | ||
".NETCoreApp,Version=v6.0": { | ||
"jSock/1.0.0": { | ||
"runtime": { | ||
"jSock.dll": {} | ||
} | ||
} | ||
} | ||
}, | ||
"libraries": { | ||
"jSock/1.0.0": { | ||
"type": "project", | ||
"serviceable": false, | ||
"sha512": "" | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<_LastSelectedProfileId>C:\Users\jackk\OneDrive\My Projects\jSock\jSock\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net.WebSockets; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace jSock; | ||
|
||
public class jSockClient : IDisposable | ||
{ | ||
|
||
public int ReceiveBufferSize { get; set; } = 8192; | ||
|
||
public async Task ConnectAsync(string url) | ||
{ | ||
if (WS != null) | ||
{ | ||
if (WS.State == WebSocketState.Open) return; | ||
else WS.Dispose(); | ||
} | ||
WS = new ClientWebSocket(); | ||
if (CTS != null) CTS.Dispose(); | ||
CTS = new CancellationTokenSource(); | ||
await WS.ConnectAsync(new Uri(url), CTS.Token); | ||
await Task.Factory.StartNew(ReceiveLoop, CTS.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); | ||
} | ||
|
||
public async Task DisconnectAsync() | ||
{ | ||
if (WS is null) return; | ||
// TODO: requests cleanup code, sub-protocol dependent. | ||
if (WS.State == WebSocketState.Open) | ||
{ | ||
CTS.CancelAfter(TimeSpan.FromSeconds(2)); | ||
await WS.CloseOutputAsync(WebSocketCloseStatus.Empty, "", CancellationToken.None); | ||
await WS.CloseAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); | ||
} | ||
WS.Dispose(); | ||
WS = null; | ||
CTS.Dispose(); | ||
CTS = null; | ||
} | ||
|
||
private async Task ReceiveLoop() | ||
{ | ||
var loopToken = CTS.Token; | ||
MemoryStream outputStream = null; | ||
WebSocketReceiveResult receiveResult = null; | ||
var buffer = new byte[ReceiveBufferSize]; | ||
try | ||
{ | ||
while (!loopToken.IsCancellationRequested) | ||
{ | ||
outputStream = new MemoryStream(ReceiveBufferSize); | ||
do | ||
{ | ||
receiveResult = await WS.ReceiveAsync(buffer, CTS.Token); | ||
if (receiveResult.MessageType != WebSocketMessageType.Close) | ||
outputStream.Write(buffer, 0, receiveResult.Count); | ||
} | ||
while (!receiveResult.EndOfMessage); | ||
if (receiveResult.MessageType == WebSocketMessageType.Close) break; | ||
outputStream.Position = 0; | ||
ResponseReceived(outputStream); | ||
} | ||
} | ||
catch (TaskCanceledException) { } | ||
finally | ||
{ | ||
outputStream?.Dispose(); | ||
} | ||
} | ||
|
||
public async Task SendMessageAsync(string message) | ||
{ | ||
var buffer = new ArraySegment<byte>(Encoding.UTF8.GetBytes(message)); | ||
await WS.SendAsync(buffer, WebSocketMessageType.Text, true, CTS.Token); | ||
} | ||
|
||
private void ResponseReceived(Stream inputStream) | ||
{ | ||
var reader = new StreamReader(inputStream); | ||
var response = reader.ReadToEnd(); | ||
Console.WriteLine(response); | ||
|
||
|
||
inputStream.Dispose(); | ||
} | ||
|
||
public void Dispose() => DisconnectAsync().Wait(); | ||
|
||
private ClientWebSocket WS; | ||
private CancellationTokenSource CTS; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> | ||
<metadata> | ||
<id>jSock</id> | ||
<version>1.0.0</version> | ||
<authors>Jack Kimmins</authors> | ||
<icon>jSockLogo.png</icon> | ||
<projectUrl>https://github.com/jackkimmins/jSock</projectUrl> | ||
<description>My C# WebSocket Server</description> | ||
<tags>websocket server c# host websockets</tags> | ||
<repository url="https://github.com/jackkimmins/jSock" /> | ||
<dependencies> | ||
<group targetFramework="net6.0" /> | ||
</dependencies> | ||
</metadata> | ||
<files> | ||
<file src="C:\Users\jackk\OneDrive\My Projects\jSock\jSock\bin\Debug\net6.0\jSock.dll" target="lib\net6.0\jSock.dll" /> | ||
<file src="C:\Users\jackk\OneDrive\My Projects\jSock\jSockLogo.png" target="\jSockLogo.png" /> | ||
</files> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4ff1f6580e2e4fdb6cfe047dd705314b561b7fcc | ||
50638fa58ba5cbdce9cefe8028ad94301dd253d5 |
Binary file not shown.
Binary file modified
BIN
+88.8 KB
(1500000%)
jSock/obj/Debug/net6.0/jSock.csproj.AssemblyReference.cache
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
749f8eda90b755fad0936193b26219ab3c7975b3 | ||
8ac89f9fd0e0a0b8894e92ab91af5e9323605ebd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd"> | ||
<metadata> | ||
<id>jSock</id> | ||
<version>1.0.0</version> | ||
<authors>Jack Kimmins</authors> | ||
<requireLicenseAcceptance>true</requireLicenseAcceptance> | ||
<license type="file">C:\Users\jackk\OneDrive\My Projects\jSock\LICENSE</license> | ||
<licenseUrl>https://aka.ms/deprecateLicenseUrl</licenseUrl> | ||
<icon>jSockLogo.png</icon> | ||
<projectUrl>https://github.com/jackkimmins/jSock</projectUrl> | ||
<description>My C# WebSocket Server</description> | ||
<repository url="https://github.com/jackkimmins/jSock" /> | ||
<dependencies> | ||
<group targetFramework="net6.0" /> | ||
</dependencies> | ||
</metadata> | ||
<files> | ||
<file src="C:\Users\jackk\OneDrive\My Projects\jSock\jSock\bin\Release\net6.0\jSock.dll" target="lib\net6.0\jSock.dll" /> | ||
<file src="C:\Users\jackk\OneDrive\My Projects\jSock\jSockLogo.png" target="\jSockLogo.png" /> | ||
</files> | ||
</package> |
4 changes: 4 additions & 0 deletions
4
jSock/obj/Release/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// <autogenerated /> | ||
using System; | ||
using System.Reflection; | ||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// Runtime Version:4.0.30319.42000 | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System; | ||
using System.Reflection; | ||
|
||
[assembly: System.Reflection.AssemblyCompanyAttribute("Stable Network")] | ||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")] | ||
[assembly: System.Reflection.AssemblyDescriptionAttribute("My C# WebSocket Server")] | ||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] | ||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")] | ||
[assembly: System.Reflection.AssemblyProductAttribute("jSock")] | ||
[assembly: System.Reflection.AssemblyTitleAttribute("jSock")] | ||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] | ||
[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/jackkimmins/jSock")] | ||
|
||
// Generated by the MSBuild WriteCodeFragment class. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
4626cc4aec7a066dcaeb864c624b79e53e8b54d0 |
10 changes: 10 additions & 0 deletions
10
jSock/obj/Release/net6.0/jSock.GeneratedMSBuildEditorConfig.editorconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
is_global = true | ||
build_property.TargetFramework = net6.0 | ||
build_property.TargetPlatformMinVersion = | ||
build_property.UsingMicrosoftNETSdkWeb = | ||
build_property.ProjectTypeGuids = | ||
build_property.InvariantGlobalization = | ||
build_property.PlatformNeutralAssembly = | ||
build_property._SupportedPlatformList = Linux,macOS,Windows | ||
build_property.RootNamespace = jSock | ||
build_property.ProjectDir = C:\Users\jackk\OneDrive\My Projects\jSock\jSock\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// <auto-generated/> | ||
global using global::System; | ||
global using global::System.Collections.Generic; | ||
global using global::System.IO; | ||
global using global::System.Linq; | ||
global using global::System.Net.Http; | ||
global using global::System.Threading; | ||
global using global::System.Threading.Tasks; |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
288ed48dc5ec7b4b7b223a888ac658059d297285 |
12 changes: 12 additions & 0 deletions
12
jSock/obj/Release/net6.0/jSock.csproj.FileListAbsolute.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\bin\Release\net6.0\jSock.deps.json | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\bin\Release\net6.0\jSock.dll | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\bin\Release\net6.0\ref\jSock.dll | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\bin\Release\net6.0\jSock.pdb | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\obj\Release\net6.0\jSock.csproj.AssemblyReference.cache | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\obj\Release\net6.0\jSock.GeneratedMSBuildEditorConfig.editorconfig | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\obj\Release\net6.0\jSock.AssemblyInfoInputs.cache | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\obj\Release\net6.0\jSock.AssemblyInfo.cs | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\obj\Release\net6.0\jSock.csproj.CoreCompileInputs.cache | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\obj\Release\net6.0\jSock.dll | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\obj\Release\net6.0\ref\jSock.dll | ||
C:\Users\jackk\OneDrive\My Projects\jSock\jSock\obj\Release\net6.0\jSock.pdb |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.