Fixed WebSocketServer
This commit is contained in:
14
Example2/Chat.cs
Normal file
14
Example2/Chat.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
namespace Example2
|
||||
{
|
||||
public class Chat : WebSocketService
|
||||
{
|
||||
protected override void onMessage(object sender, MessageEventArgs e)
|
||||
{
|
||||
Server.Send(e.Data);
|
||||
}
|
||||
}
|
||||
}
|
14
Example2/Echo.cs
Normal file
14
Example2/Echo.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
namespace Example2
|
||||
{
|
||||
public class Echo : WebSocketService
|
||||
{
|
||||
protected override void onMessage(object sender, MessageEventArgs e)
|
||||
{
|
||||
Send(e.Data);
|
||||
}
|
||||
}
|
||||
}
|
@@ -53,6 +53,8 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Echo.cs" />
|
||||
<Compile Include="Chat.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
Binary file not shown.
@@ -1,27 +1,15 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
namespace Example
|
||||
namespace Example2
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main (string[] args)
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
//WebSocketServer wssv = new WebSocketServer("ws://localhost");
|
||||
WebSocketServer wssv = new WebSocketServer("ws://localhost:4649");
|
||||
|
||||
wssv.OnConnection += (sender, e) =>
|
||||
{
|
||||
WebSocket ws = e.Socket;
|
||||
ws.OnMessage += (sender_, e_) =>
|
||||
{
|
||||
// Echo
|
||||
ws.Send(e_.Data);
|
||||
// Chat
|
||||
//wssv.Send(e_.Data);
|
||||
};
|
||||
};
|
||||
var wssv = new WebSocketServer<Echo>("ws://localhost:4649");
|
||||
//var wssv = new WebSocketServer<Chat>("ws://localhost:4649");
|
||||
|
||||
wssv.Start();
|
||||
Console.WriteLine(
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user