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: " + e.Data);
ws.Connect ();
ws.Send ("BALUS");
Console.ReadKey (true);
}
}
}
}
using System;
using WebSocketSharp;
using WebSocketSharp.Server;
namespace Example
{
public class Laputa : WebSocketBehavior
{
protected override void OnMessage (MessageEventArgs e)
{
var msg = e.Data == "BALUS"
? "I've been balused already..."
: "I'm not available now.";
Send (msg);
}
}
public class Program
{
public static void Main (string[] args)
{
var wssv = new WebSocketServer ("ws://dragonsnest.far");
wssv.AddWebSocketService<Laputa> ("/Laputa");
wssv.Start ();
Console.ReadKey (true);
wssv.Stop ();
}
}
}
ws.Compression = CompressionMethod.Deflate;
ws.SetCredentials ("nobita", "password", preAuth);
var ws = new WebSocket ("ws://example.com");
ws.SetProxy ("http://localhost:3128", "nobita", "password");
private bool send (Opcode opcode, Stream stream)
{
lock (_forSend) {
var src = stream;
var compressed = false;
var sent = false;
try {
if (_compression != CompressionMethod.None) {
stream = stream.Compress (_compression);
compressed = true;
}
sent = send (opcode, stream, compressed);
if (!sent)
error ("A send has been interrupted.", null);
}
catch (Exception ex) {
_logger.Error (ex.ToString ());
error ("An error has occurred during a send.", ex);
}
finally {
if (compressed)
stream.Dispose ();
src.Dispose ();
}
return sent;
}
}
public void CloseAsync (CloseStatusCode code, string reason)
{
string msg;
if (!CheckParametersForClose (code, reason, _client, out msg)) {
_logger.Error (msg);
error ("An error has occurred in closing the connection.", null);
return;
}
closeAsync ((ushort) code, reason);
}
private HttpRequest createHandshakeRequest()
{
var ret = HttpRequest.CreateWebSocketRequest(_uri);
var headers = ret.Headers;
if (!_origin.IsNullOrEmpty())
headers["Origin"] = _origin;
headers["Sec-WebSocket-Key"] = _base64Key;
_protocolsRequested = _protocols != null;
if (_protocolsRequested)
headers["Sec-WebSocket-Protocol"] = _protocols.ToString(", ");
_extensionsRequested = _compression != CompressionMethod.None;
if (_extensionsRequested)
headers["Sec-WebSocket-Extensions"] = createExtensions();
headers["Sec-WebSocket-Version"] = _version;
AuthenticationResponse authRes = null;
if (_authChallenge != null && _credentials != null)
{
authRes = new AuthenticationResponse(_authChallenge, _credentials, _nonceCount);
_nonceCount = authRes.NonceCount;
}
else if (_preAuth)
{
authRes = new AuthenticationResponse(_credentials);
}
if (authRes != null)
headers["Authorization"] = authRes.ToString();
if (_cookies.Count > 0)
ret.SetCookies(_cookies);
return ret;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有