예제 #1
0
        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);
        }
예제 #2
0
        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;
        }
예제 #3
0
 public Session(ClientHandler ch, EchoService es, int id)
 {
     ConnectedClientHandler = ch;
     SessionEchoService     = es;
     SessionID = id;
 }