Skip to content

Commit d0e5ae3

Browse files
committed
Fix due to the added HttpServer
1 parent 022368d commit d0e5ae3

File tree

108 files changed

+8032
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+8032
-81
lines changed

Example/bin/Debug/example.exe

0 Bytes
Binary file not shown.

Example/bin/Debug/example.exe.mdb

0 Bytes
Binary file not shown.

Example/bin/Debug/websocket-sharp.dll

85 KB
Binary file not shown.
35.9 KB
Binary file not shown.

Example/bin/Debug_Ubuntu/example.exe

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
85 KB
Binary file not shown.
35.9 KB
Binary file not shown.

Example/bin/Release/example.exe

0 Bytes
Binary file not shown.
85 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

Example1/bin/Debug/example1.exe

0 Bytes
Binary file not shown.

Example1/bin/Debug/example1.exe.mdb

0 Bytes
Binary file not shown.
85 KB
Binary file not shown.
35.9 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
85 KB
Binary file not shown.
Binary file not shown.

Example1/bin/Release/example1.exe

0 Bytes
Binary file not shown.
85 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

Example2/Example2.pidb

57 Bytes
Binary file not shown.

Example2/bin/Debug/example2.exe

0 Bytes
Binary file not shown.

Example2/bin/Debug/example2.exe.mdb

0 Bytes
Binary file not shown.
85 KB
Binary file not shown.
35.9 KB
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
85 KB
Binary file not shown.
Binary file not shown.

Example2/bin/Release/example2.exe

0 Bytes
Binary file not shown.
85 KB
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

Example3/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<appSettings>
4+
<add key="RootPath" value="../../Public" />
5+
</appSettings>
6+
</configuration>

Example3/AssemblyInfo.cs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
// Information about this assembly is defined by the following attributes.
5+
// Change them to the values specific to your project.
6+
7+
[assembly: AssemblyTitle("Example3")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("")]
12+
[assembly: AssemblyCopyright("sta")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19+
20+
[assembly: AssemblyVersion("1.0.*")]
21+
22+
// The following attributes are used to specify the signing key for the assembly,
23+
// if desired. See the Mono documentation for more information about signing.
24+
25+
//[assembly: AssemblyDelaySign(false)]
26+
//[assembly: AssemblyKeyFile("")]
27+

Example3/Chat.cs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using WebSocketSharp;
3+
using WebSocketSharp.Server;
4+
5+
namespace Example3
6+
{
7+
public class Chat : WebSocketService
8+
{
9+
protected override void onMessage(object sender, MessageEventArgs e)
10+
{
11+
Publish(e.Data);
12+
}
13+
}
14+
}

Example3/Echo.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using WebSocketSharp;
3+
using WebSocketSharp.Server;
4+
5+
namespace Example3
6+
{
7+
public class Echo : WebSocketService
8+
{
9+
protected override void onMessage(object sender, MessageEventArgs e)
10+
{
11+
Send(e.Data);
12+
}
13+
14+
protected override void onClose(object sender, CloseEventArgs e)
15+
{
16+
Console.WriteLine("[Echo] Close({0}: {1})", (ushort)e.Code, e.Code);
17+
}
18+
}
19+
}

Example3/Example3.csproj

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>9.0.21022</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<RootNamespace>Example3</RootNamespace>
11+
<AssemblyName>Example3</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15+
<DebugSymbols>true</DebugSymbols>
16+
<DebugType>full</DebugType>
17+
<Optimize>false</Optimize>
18+
<OutputPath>bin\Debug</OutputPath>
19+
<DefineConstants>DEBUG;</DefineConstants>
20+
<ErrorReport>prompt</ErrorReport>
21+
<WarningLevel>4</WarningLevel>
22+
<Externalconsole>true</Externalconsole>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>none</DebugType>
26+
<Optimize>false</Optimize>
27+
<OutputPath>bin\Release</OutputPath>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
<Externalconsole>true</Externalconsole>
31+
</PropertyGroup>
32+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Ubuntu|AnyCPU' ">
33+
<DebugSymbols>true</DebugSymbols>
34+
<DebugType>full</DebugType>
35+
<Optimize>false</Optimize>
36+
<OutputPath>bin\Debug_Ubuntu</OutputPath>
37+
<DefineConstants>DEBUG;</DefineConstants>
38+
<ErrorReport>prompt</ErrorReport>
39+
<WarningLevel>4</WarningLevel>
40+
<Externalconsole>true</Externalconsole>
41+
</PropertyGroup>
42+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_Ubuntu|AnyCPU' ">
43+
<DebugType>none</DebugType>
44+
<Optimize>false</Optimize>
45+
<OutputPath>bin\Release_Ubuntu</OutputPath>
46+
<ErrorReport>prompt</ErrorReport>
47+
<WarningLevel>4</WarningLevel>
48+
<Externalconsole>true</Externalconsole>
49+
</PropertyGroup>
50+
<ItemGroup>
51+
<Reference Include="System" />
52+
<Reference Include="System.Configuration" />
53+
</ItemGroup>
54+
<ItemGroup>
55+
<Compile Include="AssemblyInfo.cs" />
56+
<Compile Include="Program.cs" />
57+
<Compile Include="Chat.cs" />
58+
<Compile Include="Echo.cs" />
59+
</ItemGroup>
60+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
61+
<ItemGroup>
62+
<ProjectReference Include="..\websocket-sharp\websocket-sharp.csproj">
63+
<Project>{B357BAC7-529E-4D81-A0D2-71041B19C8DE}</Project>
64+
<Name>websocket-sharp</Name>
65+
</ProjectReference>
66+
</ItemGroup>
67+
<ItemGroup>
68+
<None Include="App.config" />
69+
<None Include="Public\index.html" />
70+
<None Include="Public\Js\echotest.js" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Folder Include="Public\" />
74+
<Folder Include="Public\Js\" />
75+
</ItemGroup>
76+
</Project>

Example3/Example3.pidb

8.25 KB
Binary file not shown.

Example3/Program.cs

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Configuration;
3+
using System.IO;
4+
using System.Text;
5+
using WebSocketSharp;
6+
using WebSocketSharp.Net;
7+
using WebSocketSharp.Server;
8+
9+
namespace Example3
10+
{
11+
public class Program
12+
{
13+
private static HttpServer<Echo> _httpsv;
14+
15+
public static void Main(string[] args)
16+
{
17+
_httpsv = new HttpServer<Echo>(4649);
18+
19+
_httpsv.OnResponse += (sender, e) =>
20+
{
21+
onResponse(e.Context);
22+
};
23+
24+
_httpsv.OnError += (sender, e) =>
25+
{
26+
Console.WriteLine(e.Message);
27+
};
28+
29+
_httpsv.Start();
30+
Console.WriteLine("HTTP Server listening on port: {0}\n", _httpsv.Port);
31+
32+
Console.WriteLine("Press any key to stop server...");
33+
Console.ReadLine();
34+
35+
_httpsv.Stop();
36+
}
37+
38+
private static byte[] getContent(string path)
39+
{
40+
if (path == "/")
41+
path += "index.html";
42+
43+
return _httpsv.GetFile(path);
44+
}
45+
46+
private static void onGet(HttpListenerRequest request, HttpListenerResponse response)
47+
{
48+
var content = getContent(request.RawUrl);
49+
if (content != null)
50+
{
51+
response.WriteContent(content);
52+
return;
53+
}
54+
55+
response.StatusCode = (int)HttpStatusCode.NotFound;
56+
}
57+
58+
private static void onResponse(HttpListenerContext context)
59+
{
60+
var req = context.Request;
61+
var res = context.Response;
62+
63+
if (req.HttpMethod == "GET")
64+
{
65+
onGet(req, res);
66+
return;
67+
}
68+
69+
res.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
70+
}
71+
}
72+
}

Example3/Public/Js/echotest.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* echotest.js
3+
* Derived from Echo Test of WebSocket.org (http://www.websocket.org/echo.html)
4+
*
5+
* Copyright (c) 2012 Kaazing Corporation.
6+
*
7+
*/
8+
9+
var wsUri = "ws://localhost:4649/";
10+
var output;
11+
12+
function init(){
13+
output = document.getElementById("output");
14+
testWebSocket();
15+
}
16+
17+
function testWebSocket(){
18+
websocket = new WebSocket(wsUri);
19+
20+
websocket.onopen = function(evt){
21+
onOpen(evt)
22+
};
23+
24+
websocket.onclose = function(evt){
25+
onClose(evt)
26+
};
27+
28+
websocket.onmessage = function(evt){
29+
onMessage(evt)
30+
};
31+
32+
websocket.onerror = function(evt){
33+
onError(evt)
34+
};
35+
}
36+
37+
function onOpen(evt){
38+
writeToScreen("CONNECTED");
39+
doSend("WebSocket rocks");
40+
}
41+
42+
function onClose(evt){
43+
writeToScreen("DISCONNECTED");
44+
}
45+
46+
function onMessage(evt){
47+
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data + '</span>');
48+
websocket.close();
49+
}
50+
51+
function onError(evt){
52+
writeToScreen('<span style="color: red;">ERROR: ' + evt.data + '</span>');
53+
}
54+
55+
function doSend(message){
56+
writeToScreen("SENT: " + message);
57+
websocket.send(message);
58+
}
59+
60+
function writeToScreen(message){
61+
var pre = document.createElement("p");
62+
pre.style.wordWrap = "break-word";
63+
pre.innerHTML = message;
64+
output.appendChild(pre);
65+
}
66+
67+
window.addEventListener("load", init, false);

Example3/Public/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>WebSocket Echo Test</title>
5+
<script type="text/javascript" src="/Js/echotest.js">
6+
</script>
7+
</head>
8+
<body>
9+
<h2>WebSocket Echo Test</h2>
10+
<div id="output"></div>
11+
</body>
12+
</html>

Example3/bin/Debug/Example3.exe

5.5 KB
Binary file not shown.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<appSettings>
4+
<add key="RootPath" value="../../Public" />
5+
</appSettings>
6+
</configuration>

Example3/bin/Debug/Example3.exe.mdb

1.53 KB
Binary file not shown.
132 KB
Binary file not shown.
56.6 KB
Binary file not shown.
5.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<appSettings>
4+
<add key="RootPath" value="../../Public" />
5+
</appSettings>
6+
</configuration>
1.53 KB
Binary file not shown.
132 KB
Binary file not shown.
Binary file not shown.

Example3/bin/Release/Example3.exe

5.5 KB
Binary file not shown.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<appSettings>
4+
<add key="RootPath" value="../../Public" />
5+
</appSettings>
6+
</configuration>
131 KB
Binary file not shown.
5.5 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<appSettings>
4+
<add key="RootPath" value="../../Public" />
5+
</appSettings>
6+
</configuration>
Binary file not shown.

README.md

+19-1

websocket-sharp.sln

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example1", "Example1\Exampl
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example2", "Example2\Example2.csproj", "{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example3", "Example3\Example3.csproj", "{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -49,6 +51,14 @@ Global
4951
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
5052
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
5153
{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}.Release|Any CPU.Build.0 = Release|Any CPU
54+
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU
55+
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU
56+
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57+
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Debug|Any CPU.Build.0 = Debug|Any CPU
58+
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Release_Ubuntu|Any CPU.ActiveCfg = Release_Ubuntu|Any CPU
59+
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU
60+
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}.Release|Any CPU.Build.0 = Release|Any CPU
5262
EndGlobalSection
5363
GlobalSection(MonoDevelopProperties) = preSolution
5464
StartupItem = websocket-sharp\websocket-sharp.csproj

0 commit comments

Comments
 (0)