Fix due to the added HttpServer
This commit is contained in:
6
Example3/App.config
Normal file
6
Example3/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="RootPath" value="../../Public" />
|
||||
</appSettings>
|
||||
</configuration>
|
27
Example3/AssemblyInfo.cs
Normal file
27
Example3/AssemblyInfo.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("Example3")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("sta")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
14
Example3/Chat.cs
Normal file
14
Example3/Chat.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
namespace Example3
|
||||
{
|
||||
public class Chat : WebSocketService
|
||||
{
|
||||
protected override void onMessage(object sender, MessageEventArgs e)
|
||||
{
|
||||
Publish(e.Data);
|
||||
}
|
||||
}
|
||||
}
|
19
Example3/Echo.cs
Normal file
19
Example3/Echo.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
namespace Example3
|
||||
{
|
||||
public class Echo : WebSocketService
|
||||
{
|
||||
protected override void onMessage(object sender, MessageEventArgs e)
|
||||
{
|
||||
Send(e.Data);
|
||||
}
|
||||
|
||||
protected override void onClose(object sender, CloseEventArgs e)
|
||||
{
|
||||
Console.WriteLine("[Echo] Close({0}: {1})", (ushort)e.Code, e.Code);
|
||||
}
|
||||
}
|
||||
}
|
76
Example3/Example3.csproj
Normal file
76
Example3/Example3.csproj
Normal file
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Example3</RootNamespace>
|
||||
<AssemblyName>Example3</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug_Ubuntu|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug_Ubuntu</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release_Ubuntu|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Release_Ubuntu</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Chat.cs" />
|
||||
<Compile Include="Echo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\websocket-sharp\websocket-sharp.csproj">
|
||||
<Project>{B357BAC7-529E-4D81-A0D2-71041B19C8DE}</Project>
|
||||
<Name>websocket-sharp</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="Public\index.html" />
|
||||
<None Include="Public\Js\echotest.js" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Public\" />
|
||||
<Folder Include="Public\Js\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
BIN
Example3/Example3.pidb
Normal file
BIN
Example3/Example3.pidb
Normal file
Binary file not shown.
72
Example3/Program.cs
Normal file
72
Example3/Program.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Net;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
namespace Example3
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static HttpServer<Echo> _httpsv;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
_httpsv = new HttpServer<Echo>(4649);
|
||||
|
||||
_httpsv.OnResponse += (sender, e) =>
|
||||
{
|
||||
onResponse(e.Context);
|
||||
};
|
||||
|
||||
_httpsv.OnError += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
};
|
||||
|
||||
_httpsv.Start();
|
||||
Console.WriteLine("HTTP Server listening on port: {0}\n", _httpsv.Port);
|
||||
|
||||
Console.WriteLine("Press any key to stop server...");
|
||||
Console.ReadLine();
|
||||
|
||||
_httpsv.Stop();
|
||||
}
|
||||
|
||||
private static byte[] getContent(string path)
|
||||
{
|
||||
if (path == "/")
|
||||
path += "index.html";
|
||||
|
||||
return _httpsv.GetFile(path);
|
||||
}
|
||||
|
||||
private static void onGet(HttpListenerRequest request, HttpListenerResponse response)
|
||||
{
|
||||
var content = getContent(request.RawUrl);
|
||||
if (content != null)
|
||||
{
|
||||
response.WriteContent(content);
|
||||
return;
|
||||
}
|
||||
|
||||
response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
}
|
||||
|
||||
private static void onResponse(HttpListenerContext context)
|
||||
{
|
||||
var req = context.Request;
|
||||
var res = context.Response;
|
||||
|
||||
if (req.HttpMethod == "GET")
|
||||
{
|
||||
onGet(req, res);
|
||||
return;
|
||||
}
|
||||
|
||||
res.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
|
||||
}
|
||||
}
|
||||
}
|
67
Example3/Public/Js/echotest.js
Normal file
67
Example3/Public/Js/echotest.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* echotest.js
|
||||
* Derived from Echo Test of WebSocket.org (http://www.websocket.org/echo.html)
|
||||
*
|
||||
* Copyright (c) 2012 Kaazing Corporation.
|
||||
*
|
||||
*/
|
||||
|
||||
var wsUri = "ws://localhost:4649/";
|
||||
var output;
|
||||
|
||||
function init(){
|
||||
output = document.getElementById("output");
|
||||
testWebSocket();
|
||||
}
|
||||
|
||||
function testWebSocket(){
|
||||
websocket = new WebSocket(wsUri);
|
||||
|
||||
websocket.onopen = function(evt){
|
||||
onOpen(evt)
|
||||
};
|
||||
|
||||
websocket.onclose = function(evt){
|
||||
onClose(evt)
|
||||
};
|
||||
|
||||
websocket.onmessage = function(evt){
|
||||
onMessage(evt)
|
||||
};
|
||||
|
||||
websocket.onerror = function(evt){
|
||||
onError(evt)
|
||||
};
|
||||
}
|
||||
|
||||
function onOpen(evt){
|
||||
writeToScreen("CONNECTED");
|
||||
doSend("WebSocket rocks");
|
||||
}
|
||||
|
||||
function onClose(evt){
|
||||
writeToScreen("DISCONNECTED");
|
||||
}
|
||||
|
||||
function onMessage(evt){
|
||||
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data + '</span>');
|
||||
websocket.close();
|
||||
}
|
||||
|
||||
function onError(evt){
|
||||
writeToScreen('<span style="color: red;">ERROR: ' + evt.data + '</span>');
|
||||
}
|
||||
|
||||
function doSend(message){
|
||||
writeToScreen("SENT: " + message);
|
||||
websocket.send(message);
|
||||
}
|
||||
|
||||
function writeToScreen(message){
|
||||
var pre = document.createElement("p");
|
||||
pre.style.wordWrap = "break-word";
|
||||
pre.innerHTML = message;
|
||||
output.appendChild(pre);
|
||||
}
|
||||
|
||||
window.addEventListener("load", init, false);
|
12
Example3/Public/index.html
Normal file
12
Example3/Public/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>WebSocket Echo Test</title>
|
||||
<script type="text/javascript" src="/Js/echotest.js">
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h2>WebSocket Echo Test</h2>
|
||||
<div id="output"></div>
|
||||
</body>
|
||||
</html>
|
BIN
Example3/bin/Debug/Example3.exe
Executable file
BIN
Example3/bin/Debug/Example3.exe
Executable file
Binary file not shown.
6
Example3/bin/Debug/Example3.exe.config
Normal file
6
Example3/bin/Debug/Example3.exe.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="RootPath" value="../../Public" />
|
||||
</appSettings>
|
||||
</configuration>
|
BIN
Example3/bin/Debug/Example3.exe.mdb
Normal file
BIN
Example3/bin/Debug/Example3.exe.mdb
Normal file
Binary file not shown.
BIN
Example3/bin/Debug/websocket-sharp.dll
Executable file
BIN
Example3/bin/Debug/websocket-sharp.dll
Executable file
Binary file not shown.
BIN
Example3/bin/Debug/websocket-sharp.dll.mdb
Normal file
BIN
Example3/bin/Debug/websocket-sharp.dll.mdb
Normal file
Binary file not shown.
BIN
Example3/bin/Debug_Ubuntu/Example3.exe
Executable file
BIN
Example3/bin/Debug_Ubuntu/Example3.exe
Executable file
Binary file not shown.
6
Example3/bin/Debug_Ubuntu/Example3.exe.config
Normal file
6
Example3/bin/Debug_Ubuntu/Example3.exe.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="RootPath" value="../../Public" />
|
||||
</appSettings>
|
||||
</configuration>
|
BIN
Example3/bin/Debug_Ubuntu/Example3.exe.mdb
Normal file
BIN
Example3/bin/Debug_Ubuntu/Example3.exe.mdb
Normal file
Binary file not shown.
BIN
Example3/bin/Debug_Ubuntu/websocket-sharp.dll
Executable file
BIN
Example3/bin/Debug_Ubuntu/websocket-sharp.dll
Executable file
Binary file not shown.
BIN
Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb
Normal file
BIN
Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb
Normal file
Binary file not shown.
BIN
Example3/bin/Release/Example3.exe
Executable file
BIN
Example3/bin/Release/Example3.exe
Executable file
Binary file not shown.
6
Example3/bin/Release/Example3.exe.config
Normal file
6
Example3/bin/Release/Example3.exe.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="RootPath" value="../../Public" />
|
||||
</appSettings>
|
||||
</configuration>
|
BIN
Example3/bin/Release/websocket-sharp.dll
Executable file
BIN
Example3/bin/Release/websocket-sharp.dll
Executable file
Binary file not shown.
BIN
Example3/bin/Release_Ubuntu/Example3.exe
Executable file
BIN
Example3/bin/Release_Ubuntu/Example3.exe
Executable file
Binary file not shown.
6
Example3/bin/Release_Ubuntu/Example3.exe.config
Normal file
6
Example3/bin/Release_Ubuntu/Example3.exe.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="RootPath" value="../../Public" />
|
||||
</appSettings>
|
||||
</configuration>
|
BIN
Example3/bin/Release_Ubuntu/websocket-sharp.dll
Executable file
BIN
Example3/bin/Release_Ubuntu/websocket-sharp.dll
Executable file
Binary file not shown.
Reference in New Issue
Block a user