本文整理汇总了C#中Fleck.WebSocketServer类的典型用法代码示例。如果您正苦于以下问题:C# WebSocketServer类的具体用法?C# WebSocketServer怎么用?C# WebSocketServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketServer类属于Fleck命名空间,在下文中一共展示了WebSocketServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: InitializeListener
public void InitializeListener()
{
var server = new WebSocketServer("ws://localhost:8989/FileTail");
server.Start(socket =>
{
socket.OnOpen = () => Console.WriteLine("Open!");
socket.OnClose = () => Console.WriteLine("Close!");
socket.OnMessage = message => socket.Send(message);
});
//var listener = new TcpListener(IPAddress.Loopback, 8989);
//try
//{
// listener.Start();
// using (var client = listener.AcceptTcpClient())
// using (var stream = client.GetStream())
// using (var reader = new StreamReader(stream))
// using (var writer = new StreamWriter(stream))
// {
// writer.WriteLine("HTTP/1.1 101 Web Socket Protocol Handshake");
// writer.WriteLine("Upgrade: WebSocket");
// writer.WriteLine("Connection: Upgrade");
// writer.WriteLine("WebSocket-Origin: http://localhost:50695");
// writer.WriteLine("WebSocket-Location: ws://localhost:8989/websession");
// writer.WriteLine("");
// }
// listener.Stop();
//}
//catch
//{ }
}
开发者ID:jamessantiago,项目名称:jamescms,代码行数:32,代码来源:WebSocketListener.cs
示例2: InitializeServer
private static void InitializeServer()
{
var server = new WebSocketServer("ws://localhost:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
Console.WriteLine("Connected to " + socket.ConnectionInfo.ClientIpAddress);
_clients.Add(socket);
};
socket.OnClose = () =>
{
Console.WriteLine("Disconnected from " + socket.ConnectionInfo.ClientIpAddress);
_clients.Remove(socket);
};
socket.OnMessage = message =>
{
Console.WriteLine(message);
};
});
_serverInitialized = true;
Console.ReadLine();
}
开发者ID:Vangos,项目名称:KinectHtml5,代码行数:28,代码来源:Program.cs
示例3: Run
public void Run(string serverUrl)
{
var server = new WebSocketServer(serverUrl);
server.Start(socket =>
{
socket.OnOpen = () =>
{
onClientConnected(socket);
};
socket.OnClose = () =>
{
onClientDisconnected(socket, null);
};
socket.OnMessage = (message) =>
{
onClientMessage(socket, message, null);
};
socket.OnBinary = (message) =>
{
onClientMessage(socket, message, null);
};
});
}
开发者ID:HclX,项目名称:HomeLink,代码行数:26,代码来源:Proxy.cs
示例4: Main
static void Main(string[] args)
{
var server = new WebSocketServer("ws://localhost:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
Console.WriteLine("Open: " + socket.ConnectionInfo.Id);
};
socket.OnClose = () =>
{
Console.WriteLine("Close: " + socket.ConnectionInfo.Id);
ChatServer.Instance.ClientLost(socket);
};
socket.OnMessage = message =>
{
Console.WriteLine("Message: " + socket.ConnectionInfo.Id);
Console.WriteLine(" " + message);
ChatServer.Instance.Accept(socket, message);
};
});
Console.ReadLine();
}
开发者ID:oricalvo,项目名称:course-advfed-sap-2015-07,代码行数:26,代码来源:Program.cs
示例5: InitializeConnection
private static void InitializeConnection()
{
var server = new WebSocketServer("ws://0.0.0.0:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
_clients.Add(socket);
};
socket.OnClose = () =>
{
_clients.Remove(socket);
};
socket.OnMessage = message =>
{
switch (message)
{
case "Color":
_mode = Mode.Color;
break;
case "Depth":
_mode = Mode.Depth;
break;
default:
break;
}
Console.WriteLine("Switched to " + message);
};
});
}
开发者ID:dschie,项目名称:Kinect-HTML5,代码行数:34,代码来源:Program.cs
示例6: Init
public void Init(string port)
{
FleckLog.Level = LogLevel.Warn;
_allSockets = new List<IWebSocketConnection>();
var websocketaddr = "ws://127.0.0.1:" + port;
Logger.WriteMinorEvent("Attempting to open a WebSocketServer on " + websocketaddr);
_server = new WebSocketServer(websocketaddr);
try
{
_server.Start(socket =>
{
socket.OnOpen = () =>
{
Debug.WriteLine("Backend received an request to open a BloomWebSocketServer socket");
_allSockets.Add(socket);
};
socket.OnClose = () =>
{
Debug.WriteLine("Backend received an request to close BloomWebSocketServer socket");
_allSockets.Remove(socket);
};
});
}
catch (SocketException ex)
{
Logger.WriteEvent("Opening a WebSocketServer on " + websocketaddr + " failed. Error = " + ex);
ErrorReport.NotifyUserOfProblem(ex, "Bloom cannot start properly (cannot set up some internal communications){0}{0}" +
"What caused this?{0}" +
"Possibly another version of Bloom is running, perhaps not very obviously.{0}{0}" +
"What can you do?{0}" +
"Click OK, then exit Bloom and restart your computer.{0}" +
"If the problem keeps happening, click 'Details' and report the problem to the developers.", Environment.NewLine);
}
}
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:35,代码来源:BloomWebSocketServer.cs
示例7: APIServer
private APIServer()
{
stopwatchOffset = 0;
trackTime = new Stopwatch();
ip = getIpAddress();
server = new WebSocketServer("ws://" + ip + ":" + API_PORT);
}
开发者ID:joshuaegclark,项目名称:SAMSS6.0,代码行数:7,代码来源:APIServer.cs
示例8: ChatHandler
public ChatHandler()
{
chatSocketList = new List<IWebSocketConnection>();
var server = new WebSocketServer("ws://localhost:5002/chat");
server.Start(socket =>
{
socket.OnOpen = () => {
Console.WriteLine("User connected to Chat");
chatSocketList.Add(socket);
//socket.Send(JsonConvert.SerializeObject(Main.ludo.Chat));
};
socket.OnClose = () => {
chatSocketList.Remove(socket);
};
socket.OnMessage = message =>
{
Console.WriteLine("[ChatHandler] Incoming: " + message);
Message msg = JsonConvert.DeserializeObject<Message>(message);
msg.TimeStamp = DateTime.Now;
Main.ludo.Chat.Add(msg);
foreach (var s in chatSocketList.ToList())
{
s.Send(JsonConvert.SerializeObject(msg));
}
};
});
}
开发者ID:Cir0X,项目名称:ludo,代码行数:29,代码来源:ChatHandler.cs
示例9: Start
public void Start()
{
List<IWebSocketConnection> sockets = new List<IWebSocketConnection>();
Fleck.WebSocketServer server = new Fleck.WebSocketServer("ws://127.0.0.1:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
Console.WriteLine("Connection open.");
sockets.Add(socket);
};
socket.OnClose = () =>
{
Console.WriteLine("Connection closed.");
sockets.Remove(socket);
};
socket.OnMessage = message =>
{
Console.WriteLine("Client says: " + message);
sockets.ToList().ForEach(s => s.Send(" client says:" + message));
};
});
string input = Console.ReadLine();
while (input != "exit")
{
sockets.ToList().ForEach(s => s.Send(input));
input = Console.ReadLine();
}
}
开发者ID:bvelji,项目名称:70-480_Practice,代码行数:32,代码来源:HelloServer.cs
示例10: Connec
public Connec()
{
asdassd.Add("MenuGetir", Getir);
Method_Call M = new Method_Call();
//Type Ty = Type.GetType("InanYalcin_FleckSoket.Model.Site." + message, true);
//var b = Ty;
//var Deger = M.Method(Ty,message );
FleckLog.Level = LogLevel.Debug;
var allSockets = new List<IWebSocketConnection>();
var server = new WebSocketServer("ws://localhost:8181/consoleappsample");
server.Start(socket =>
{
socket.OnOpen = () =>
{
allSockets.Add(socket);
};
socket.OnClose = () =>
{
allSockets.Remove(socket);
};
socket.OnMessage = message =>
{
//var c = System.Activator.CreateInstance(Type.GetType("InanYalcin_FleckSoket.Model.Site." + message));
var c = asdassd[message]();
socket.Send(JsonConvert.SerializeObject(c, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
//allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
};
});
}
开发者ID:rwx7540,项目名称:inanyalcin,代码行数:31,代码来源:Connec.cs
示例11: init
public static void init()
{
FleckLog.Level = LogLevel.Debug;
allSockets = new List<IWebSocketConnection>();
server = new WebSocketServer("ws://localhost:1337");
server.Start(socket =>
{
socket.OnOpen = () =>
{
Console.WriteLine("Open!");
allSockets.Add(socket);
};
socket.OnClose = () =>
{
Console.WriteLine("Close!");
allSockets.Remove(socket);
};
socket.OnMessage = message =>
{
Console.WriteLine(message);
if (message == "SENDMEANIMAGE")
{
Kinect.sendImage();
}
};
});
}
开发者ID:sydlawrence,项目名称:ubelly-kinect,代码行数:27,代码来源:Kinect.cs
示例12: Main
static void Main()
{
FleckLog.Level = LogLevel.Debug;
var allSockets = new List<IWebSocketConnection>();
var server = new WebSocketServer("ws://0.0.0.0:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
Console.WriteLine("Open!");
allSockets.Add(socket);
};
socket.OnClose = () =>
{
Console.WriteLine("Close!");
allSockets.Remove(socket);
};
socket.OnMessage = message =>
{
Console.WriteLine(message);
// process the message
dynamic gameState = gameServer.MessageBroker.ProcessMessage(message);
string serializedState = _serializer.Serialize(gameState);
//allSockets.ToList().ForEach(s => s.Send("Echo: "));
};
});
var input = Console.ReadLine();
while (input != "exit")
{
input = Console.ReadLine();
}
}
开发者ID:mrtown,项目名称:engine,代码行数:35,代码来源:WebsocketHandler.cs
示例13: StartServer
public void StartServer()
{
var allSockets = new List<IWebSocketConnection>();
var server = new WebSocketServer("ws://localhost:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
//Console.WriteLine("Open!");
allSockets.Add(socket);
};
socket.OnClose = () =>
{
//Console.WriteLine("Close!");
allSockets.Remove(socket);
};
socket.OnMessage = message =>
{
var date = DateTime.Now.ToShortTimeString();
//SaveMessage(socket.ConnectionInfo.Id, message);
//Console.WriteLine(message);
allSockets.ToList().ForEach(s => s.Send(date + ": " + message));
};
});
//server.Close();
//ServiceHost host = new ServiceHost(typeof(MyService));
}
开发者ID:sonpv90,项目名称:storage-andreish,代码行数:30,代码来源:ChatService.svc.cs
示例14: Main
static void Main(string[] args)
{
var webSocketServer = new WebSocketServer("ws://127.0.0.1:8081");
var sockets = new List<IWebSocketConnection>();
webSocketServer.Start(socket =>
{
socket.OnOpen = () =>
{
sockets.Add(socket);
};
socket.OnMessage = mensagem =>
{
foreach (var s in sockets)
{
s.Send(mensagem);
}
};
socket.OnClose = () =>
{
sockets.Remove(socket);
};
});
Console.ReadKey();
}
开发者ID:branux,项目名称:20480-Turma-KaSolution-Noturno-08-Set-15,代码行数:28,代码来源:Program.cs
示例15: InitializeSockets
public void InitializeSockets()
{
_sockets = new List<IWebSocketConnection>();
var server = new WebSocketServer("ws://localhost:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
_sockets.Add(socket);
};
socket.OnClose = () =>
{
_sockets.Remove(socket);
};
socket.OnMessage = message =>
{
JavaScriptSerializer js = new JavaScriptSerializer();
dynamic obj = js.Deserialize<object>(message);
dynamic listaComandos = obj["Palabras"];
Audio.añadirComandos(listaComandos);
};
});
}
开发者ID:CesarGamarra,项目名称:ServidorKinect-PizarraVirtual,代码行数:26,代码来源:Conexion.cs
示例16: Main
static void Main()
{
FleckLog.Level = LogLevel.Debug;
var allSockets = new List<IWebSocketConnection>();
var server = new WebSocketServer("ws://localhost:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
Console.WriteLine("连接成功");
allSockets.Add(socket);
};
socket.OnClose = () =>
{
Console.WriteLine("连接已关闭");
allSockets.Remove(socket);
};
socket.OnMessage = message =>
{
Console.WriteLine("客户端发来消息"+message);
//allSockets.ForEach(s => s.Send(message));
};
});
var input = Console.ReadLine();
while (input != "exit")
{
foreach (var socket in allSockets.ToList())
{
socket.Send(input);
}
input = Console.ReadLine();
}
}
开发者ID:pear171902790,项目名称:Html5,代码行数:34,代码来源:Server.cs
示例17: StartWebSocketServer
public bool StartWebSocketServer() {
WSRConfig cfg = WSRConfig.GetInstance();
int port = cfg.WebSocket;
if (port < 0) { return false; }
if (cfg.WSSmooth) filter1 = new DepthFilteredSmoothing();
if (cfg.WSAverage) filter2 = new DepthAveragedSmoothing();
ImageFormat format = cfg.WSType == "png" ? ImageFormat.Png : ImageFormat.Jpeg;
Sockets = new List<IWebSocketConnection>();
Server = new WebSocketServer("ws://localhost:" + port);
Server.Start(socket => {
socket.OnOpen = () => {
cfg.logInfo("WEBSCK", "Connected to: " + socket.ConnectionInfo.ClientIpAddress);
lock (Sockets) { Sockets.Add(socket); }
};
socket.OnClose = () => {
cfg.logInfo("WEBSCK", "Disconnected from: " + socket.ConnectionInfo.ClientIpAddress);
lock (Sockets) { Sockets.Remove(socket); }
};
socket.OnMessage = message => {
SendWebSocket(socket, GreenScreen(message), format);
};
});
return true;
}
开发者ID:jdelhommeau,项目名称:WSRMacro,代码行数:28,代码来源:WSRWebSocket.cs
示例18: Start
public static void Start()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
FleckLog.Level = LogLevel.Debug;
var allSockets = new List<IWebSocketConnection>();
var server = new WebSocketServer("ws://0.0.0.0:8181");
server.Start(socket =>
{
socket.OnOpen = () =>
{
Debug.WriteLine("Open!");
allSockets.Add(socket);
};
socket.OnClose = () =>
{
Debug.WriteLine("Close!");
allSockets.Remove(socket);
};
socket.OnMessage = message =>
{
var jsonObj = serializer.Deserialize<MessageFormat>(message);
Debug.WriteLine("[username]: " + jsonObj.username);
Debug.WriteLine("[nickname]: " + jsonObj.nickname);
Debug.WriteLine("[content]: " + jsonObj.content);
Debug.WriteLine("");
string msg = String.Format("{0}: {1}", jsonObj.nickname, jsonObj.content);
allSockets.ToList().ForEach(s => s.Send(msg));
};
});
}
开发者ID:monzy613,项目名称:fakebook-csharp-server,代码行数:31,代码来源:Server.cs
示例19: Initialize
private void Initialize()
{
var server = new WebSocketServer("ws://0.0.0.0:8282");
server.Start(socket =>
{
socket.OnOpen = () =>
{
_clients.Add(socket);
};
socket.OnClose = () =>
{
_clients.Remove(socket);
};
socket.OnMessage = message =>
{
//var eventObject = Serialization.DeserializeEnvelope<ContractMarker>(message);
//_commandReceivedSubject.OnNext(eventObject);
Tracer.Trace(message);
};
socket.OnBinary = data =>
{
Tracer.Trace("Binary data sent from client o_0");
};
});
}
开发者ID:chaliy,项目名称:moov-the-sphero,代码行数:30,代码来源:ServerManager.cs
示例20: Main
static void Main(string[] args)
{
string url = args.Length > 0 ? args[0] : "ws://localhost:8181";
server = new WebSocketServer(url);
server.Start(socket =>
{
socket.OnOpen = () => Open(socket);
socket.OnClose = () => Close(socket);
socket.OnMessage = message => Receive(socket, message);
});
Console.WriteLine("Type a message to send to the client (type 'exit' to close):");
var input = Console.ReadLine();
while (input != "exit")
{
foreach (IWebSocketConnection socket in allSockets)
{
//standard socket raw send method
socket.Send(input);
//find our dynamic sockpuppet for this socket, and call a dynamic method
clientDynamicWindows[socket.ConnectionInfo.Id].document.write("called from a dynamic object method: " + input);
//find our strongly typed interface sockpuppet for this socket, and call a typed method (that matches a method for our chosen context on the client)\
clientWindows[socket.ConnectionInfo.Id].alert("called from an interface method: " + input);
}
input = Console.ReadLine();
}
}
开发者ID:developerdizzle,项目名称:SockPuppet,代码行数:33,代码来源:Program.cs
注:本文中的Fleck.WebSocketServer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论