/// <summary> /// Initializes a new instance of the <see cref="ServerConnection"/> class. /// </summary> /// <param name="port">The port.</param> /// <param name="ch">The ch.</param> public ServerConnection(int port, IClientHandler ch) { this.port = port; this.ch = ch; this.keepOpen = "keep open"; this.closeConnection = "close connection"; }
private void NewMethod() { // This server generates a new connection for each client while (true) { TcpClient client = listener.AcceptTcpClient(); // waiting for client that wants to connect and accept it client = listener.AcceptTcpClient(); // try { Console.WriteLine("Client connected"); // handle this client (seperate thread) IClientHandler currClientHandler = new IClientHandler(client); currClientHandler.userConnected += CurrClientHandler_userConnected; currClientHandler.userDisconnected += CurrClientHandler_userDisconnected; currClientHandler.userSentMessage += CurrClientHandler_userSentMessage; System.Threading.ThreadStart ts = new System.Threading.ThreadStart(currClientHandler.HandleClient); System.Threading.Thread t = new System.Threading.Thread(ts); t.Start(); } // catch (Exception ex) // { // Console.WriteLine(ex.Message); // } } }
public Server(IClientHandler ch) { this.ch = ch; string ipAddress = ConfigurationManager.AppSettings["ip"]; IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ipAddress), Convert.ToInt32(ConfigurationManager.AppSettings["port"])); listener = new TcpListener(ep); }
private void CurrClientHandler_userSentMessage(IClientHandler sender, string MessageContent) { IClientHandler c = sender; Console.WriteLine(c.UserName + " sending message: " + MessageContent); sendMessageToAllUsers(c, MessageContent); // notifty the graphics UserSentMessage(this, MessageContent); }
private void CurrClientHandler_userDisconnected(IClientHandler sender, string MessageContent) { IClientHandler c = sender; connectedUsers.Remove(c.UserName); Console.WriteLine(c.UserName + " has disconnected"); sendMessageToAllUsers(c, MessageContent); // notifty the graphics UserDisconnected(this, c.UserName); }
private void CurrClientHandler_userConnected(IClientHandler sender, string MessageContent) { IClientHandler c = sender; connectedUsers.Add(c.UserName, c); Console.WriteLine(c.UserName + " has connected"); // send message to all users sendMessageToAllUsers(c, MessageContent); // notifty the graphics UserConected(this, c.UserName); }
private void sendMessageToAllUsers(IClientHandler sendingUser, string MessageContent) { IClientHandler c = sendingUser; Console.WriteLine(c.UserName + " sendMessageToAllUsers message: " + MessageContent); foreach (KeyValuePair <string, IClientHandler> currUser in connectedUsers) { if (c != currUser.Value) { try { currUser.Value.sendMessage(MessageContent); } catch { Console.WriteLine("error sending message to: " + currUser.Key); } } } }
/// <summary> /// Initializes a new instance of the <see cref="Controller"/> class. /// </summary> /// <param name="model">The model.</param> /// <param name="clientHandler">The client handler.</param> /// <exception cref="System.ArgumentNullException"> /// model /// or /// clientHandler /// </exception> public Controller(IModel model, IClientHandler clientHandler) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (clientHandler == null) { throw new ArgumentNullException(nameof(clientHandler)); } this.model = model; this.clientHandler = clientHandler; commands = new Dictionary <string, ICommand>(); commands.Add("generate", new GenerateCommand(model)); commands.Add("close", new CloseCommand(model)); commands.Add("join", new JoinCommand(model)); commands.Add("play", new PlayCommand(model)); commands.Add("solve", new SolveCommand(model)); commands.Add("list", new ListCommand(model)); commands.Add("start", new StartCommand(model)); }
/// <summary> /// constructor /// </summary> /// <param name="port">of the connection</param> /// <param name="ip">of the connection</param> /// <param name="ch">to handle incomming clients</param> public Server(int port, IPAddress ip, IClientHandler ch) { this.ch = ch; ep = new IPEndPoint(ip, port); }
/// <summary> /// Initializes a new instance of the <see cref="Server"/> class. /// </summary> /// <param name="port">The port.</param> /// <param name="ch">The ch.</param> public Server(int port, IClientHandler ch) { this.port = port; this.ch = ch; listener = null; }
/// <summary> /// Initializes a new instance of the <see cref="Server"/> class. /// </summary> /// <param name="port">The port.</param> /// <param name="ch">The ch.</param> public Server(int port, IClientHandler ch) { this.port = port; this.ch = ch; }
/// <summary> /// Sets the client handler. /// </summary> /// <param name="ch">The ch.</param> public void SetClientHandler(IClientHandler ch) { this.clientHandler = ch; }
/// <summary> /// constructor of the <see cref="Server" /> class. /// </summary> /// <param name="ch">The client handler.</param> public Server(IClientHandler ch) { _ch = ch; }
/// <summary> /// Add a <see cref="ClientHandler" />. /// </summary> /// <param name="userId">The client's <see cref="User" /> Id.</param> /// <param name="clientHandler">The <see cref="ClientHandler" /> to add.</param> public void AddClientHandler(int userId, IClientHandler clientHandler) { clientHandlersIndexedByUserId.Add(userId, clientHandler); }
/// <summary> /// Initializes a new instance of the <see cref="MyServer"/> class. /// </summary> /// <param name="port">The port.</param> /// <param name="ch">The ch.</param> public MyServer(string port, IClientHandler ch) { this.portNum = int.Parse(port); this.ch = ch; }