private Session StartSession(Socket client) { EchoService es = new EchoService(); ClientHandler ch = new ClientHandler(client, es); Session session; int clientId = int.Parse(ch.reader.ReadLine()); if (clientId != -1) { session = GetSession(clientId); ch.es = session.ConnectedClientHandler.es; session.ConnectedClientHandler = ch; } else { lastSessionId++; clientId = lastSessionId; session = new Session(ch, es, lastSessionId); listOfSessions.Add(lastSessionId, session); } session.ConnectedClientHandler.writer.WriteLine(clientId); return(session); }
public ClientHandler(Socket clientS, EchoService eService) { clientSocket = clientS; netStream = new NetworkStream(clientSocket); reader = new StreamReader(netStream); writer = new StreamWriter(netStream); writer.AutoFlush = true; es = eService; }
public Session(ClientHandler ch, EchoService es, int id) { ConnectedClientHandler = ch; SessionEchoService = es; SessionID = id; }