public async Task Initialize() { var input = string.Empty; _server = new WebSocketServer($"{Url}:{_port}"); await Task.Run(() => _server.Start(socket => { socket.OnOpen = () => { _msgText.Show($"New client connected: {socket.ConnectionInfo.ClientIpAddress}"); ConnectedSockets.Add(socket); }; socket.OnClose = () => { _msgText.Show($"Client disconnected: {socket.ConnectionInfo.ClientIpAddress}"); ConnectedSockets.Remove(socket); }; socket.OnMessage = message => { _msgText.Show(message); ConnectedSockets.ToList().ForEach(s => s.Send(message)); }; })); }
public async Task Initialize() { do { _msgText.Show("Please write your nickname: "); NickName = Console.ReadLine(); } while (string.IsNullOrWhiteSpace(NickName)); await Connect(); Task = ListenToMessages(); }