本文整理汇总了C#中Fleck.WebSocketServer类的典型用法代码示例。如果您正苦于以下问题:C# WebSocketServer类的具体用法?C# WebSocketServer怎么用?C# WebSocketServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketServer类属于Fleck命名空间,在下文中一共展示了WebSocketServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
//{ }
}
示例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();
}
示例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);
};
});
}
示例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();
}
示例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);
};
});
}
示例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);
}
}
示例7: APIServer
private APIServer()
{
stopwatchOffset = 0;
trackTime = new Stopwatch();
ip = getIpAddress();
server = new WebSocketServer("ws://" + ip + ":" + API_PORT);
}
示例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));
}
};
});
}
示例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();
}
}
示例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));
};
});
}
示例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();
}
};
});
}
示例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();
}
}
示例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));
}
示例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();
}
示例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);
};
});
}