本文整理汇总了C#中Fleck.WebSocketServer.Start方法的典型用法代码示例。如果您正苦于以下问题:C# WebSocketServer.Start方法的具体用法?C# WebSocketServer.Start怎么用?C# WebSocketServer.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fleck.WebSocketServer
的用法示例。
在下文中一共展示了WebSocketServer.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: 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
//{ }
}
示例3: 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);
};
});
}
示例4: 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));
}
示例5: 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();
}
}
示例6: 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);
};
});
}
示例7: 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);
};
});
}
示例8: 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();
}
示例9: 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;
}
示例10: 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();
}
示例11: 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();
}
}
示例12: 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));
};
});
}
示例13: 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();
}
}
示例14: 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();
}
};
});
}
示例15: 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));
};
});
}