Modified README.md
This commit is contained in:
parent
815d12f6a0
commit
5ea5828cf9
Binary file not shown.
Binary file not shown.
59
README.md
59
README.md
@ -6,6 +6,32 @@
|
||||
|
||||
### WebSocket client ###
|
||||
|
||||
```cs
|
||||
using System;
|
||||
using WebSocketSharp;
|
||||
|
||||
namespace Example {
|
||||
|
||||
public class Program {
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
using (var ws = new WebSocket("ws://dragonsnest.far/Laputa"))
|
||||
{
|
||||
ws.OnMessage += (sender, e) =>
|
||||
{
|
||||
Console.WriteLine("Laputa says: {0}", e.Data);
|
||||
};
|
||||
|
||||
ws.Connect();
|
||||
ws.Send("BALUS");
|
||||
Console.ReadKey(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Step 1 ####
|
||||
|
||||
Required namespace.
|
||||
@ -21,7 +47,7 @@ The `WebSocket` class exists in the `WebSocketSharp` namespace.
|
||||
Creating a instance of the `WebSocket` class.
|
||||
|
||||
```cs
|
||||
using (WebSocket ws = new WebSocket("ws://example.com"))
|
||||
using (var ws = new WebSocket("ws://example.com"))
|
||||
{
|
||||
...
|
||||
}
|
||||
@ -140,6 +166,37 @@ In addition, the `Close()` and `Close(code)` methods exist.
|
||||
|
||||
### WebSocket server ###
|
||||
|
||||
```cs
|
||||
using System;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
|
||||
namespace Example {
|
||||
|
||||
public class Laputa : WebSocketService
|
||||
{
|
||||
protected override void OnMessage(MessageEventArgs e)
|
||||
{
|
||||
var msg = e.Data.Equals("balus", StringComparison.InvariantCultureIgnoreCase)
|
||||
? "I've been balused already..."
|
||||
: "I'm not available now.";
|
||||
Send(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public class Program {
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var wssv = new WebSocketServiceHost<Laputa>("ws://dragonsnest.far/Laputa");
|
||||
wssv.Start();
|
||||
Console.ReadKey(true);
|
||||
wssv.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Step 1 ####
|
||||
|
||||
Required namespace.
|
||||
|
@ -1,6 +1,10 @@
|
||||
<Properties>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug_Ubuntu" />
|
||||
<MonoDevelop.Ide.Workbench />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="websocket-sharp/WebSocket.cs">
|
||||
<Files>
|
||||
<File FileName="websocket-sharp/WebSocket.cs" Line="1" Column="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user