Exemple #1
0
 public State(SessionTable sessionTable, NetworkStream socketNetworkStream, StreamReader socketReader, StreamWriter socketWriter)
 {
     this.sessionTable        = sessionTable;
     this.socketNetworkStream = socketNetworkStream;
     this.socketReader        = socketReader;
     this.socketWriter        = socketWriter;
 }
Exemple #2
0
 public ClientThread(Socket clientSocket, SessionTable sessionTable)
 {
     this.clientSocket = clientSocket;
     this.sessionTable = sessionTable;
     session           = null;
     currentState      = null;
     theThread         = new Thread(new ParameterizedThreadStart(ClientThreadFunc));
 }
Exemple #3
0
        public SDServer(ushort listeningPort, int clientBacklog)
        {
            this.listeningPort = listeningPort;
            this.clientBacklog = clientBacklog;

            // initially empty session table
            sessionTable = new SessionTable();
        }
 public ClientThread(Socket clientSocket, SessionTable sessionTable)
 {
     socketNetworkStream = new NetworkStream(clientSocket);
     socketReader        = new StreamReader(socketNetworkStream);
     socketWriter        = new StreamWriter(socketNetworkStream);
     this.clientSocket   = clientSocket;
     this.sessionTable   = sessionTable;
     session             = null;
     currentState        = null;
     theThread           = new Thread(new ParameterizedThreadStart(ClientThreadFunc));
 }
Exemple #5
0
        static void Main(string[] args)
        {
            // process cmd line
            // -prs <PRS IP address>:<PRS port>

            // create the session table
            SessionTable sessionTable = new SessionTable();

            // get the listening port from the PRS for the "SD Server" service
            string serviceName = "SD Server";
            string prsIP       = "127.0.0.1";
            ushort prsPort     = 30000;

            PRSServiceClient.prsAddress = IPAddress.Parse(prsIP);
            PRSServiceClient.prsPort    = prsPort;
            PRSServiceClient prs           = new PRSServiceClient(serviceName);
            ushort           listeningPort = prs.RequestPort();

            // create the TCP listening socket
            Socket listeningSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);

            listeningSocket.Bind(new IPEndPoint(IPAddress.Any, listeningPort));
            listeningSocket.Listen(42);     // 42 is the number of clients that can be waiting for us to accept their connection
            Console.WriteLine("Listening for clients on port " + listeningPort.ToString());

            bool done = false;

            while (!done)
            {
                // wait for a client to connect
                Console.WriteLine("Ready to accept new client");
                Socket clientSocket = listeningSocket.Accept();
                Console.WriteLine("Accepted connection from client");

                // create a thread for this client, and then return to listening for more clients
                Console.WriteLine("Launch new thread for connected client");
                ClientThread clientThread = new ClientThread(clientSocket, sessionTable);
                clientThread.Start();
            }

            // close down the listening socket
            Console.WriteLine("Closing listening socket");
            listeningSocket.Close();

            // close the listening port that I received from the PRS
            prs.ClosePort();
        }
        private ulong sessionId;                // session id for this session, once opened or resumed

        public SDConnectedClient(Socket clientSocket, SessionTable sessionTable)
        {
            // save the client's socket
            this.clientSocket = clientSocket;

            // at this time, there is no stream, reader, write or thread
            reader       = null;
            writer       = null;
            stream       = null;
            clientThread = null;

            // save the server's session table
            this.sessionTable = sessionTable;

            // at this time, there is no session open
            sessionId = 0;
        }
        static void Main(string[] args)
        {
            // process cmd line
            // -prs <PRS IP address>:<PRS port>
            try
            {
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-prs")// -prs prsip:prsport
                    {
                        if (i++ < args.Length)
                        {
                            string[] parts = args[i].Split(':');
                            if (parts.Length != 2)
                            {
                                throw new Exception("Invalid PRSIP:PRSAddress format");
                            }
                            PRS_ADDRESS = parts[1];
                            PRS_PORT    = System.Convert.ToUInt16(parts[0]);
                        }
                        else
                        {
                            throw new Exception("No value for -prs option");
                        }
                    }
                    else
                    {
                        throw new Exception("Invalid cmdline parameter");
                    }
                }
            }catch (Exception ex)
            {
                Console.WriteLine("Error processing command line:" + ex);
                return;
            }
            // create the session table
            SessionTable sessionTable = new SessionTable();

            Console.WriteLine("PRS ADDRESS:" + PRS_ADDRESS);
            Console.WriteLine("PRS PORT:" + PRS_PORT);
            // get the listening port from the PRS for the "SD Server" service
            PRSClient PRS           = new PRSClient(IPAddress.Parse(PRS_ADDRESS), PRS_PORT, SERVICE_NAME);
            ushort    listeningPort = PRS.RequestPort();

            // create the TCP listening socket
            Socket listeningSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);

            listeningSocket.Bind(new IPEndPoint(IPAddress.Any, listeningPort));
            listeningSocket.Listen(CLIENT_BACKLOG);     // 42 is the number of clients that can be waiting for us to accept their connection
            Console.WriteLine("Listening for clients on port " + listeningPort.ToString());

            bool done = false;

            while (!done)
            {
                // wait for a client to connect
                Console.WriteLine("Ready to accept new client");
                Socket clientSocket = listeningSocket.Accept();
                Console.WriteLine("Accepted connection from client");

                // create a thread for this client, and then return to listening for more clients
                Console.WriteLine("Launch new thread for connected client");
                ClientThread clientThread = new ClientThread(clientSocket, sessionTable);
                clientThread.Start();
            }

            // close down the listening socket
            Console.WriteLine("Closing listening socket");
            listeningSocket.Close();

            // close the listening port that I received from the PRS
            PRS.ClosePort();
        }
Exemple #8
0
 public ReadyForSessionCmd(SessionTable sessionTable, NetworkStream socketNetworkStream, StreamReader socketReader, StreamWriter socketWriter) :
     base(sessionTable, socketNetworkStream, socketReader, socketWriter)
 {
 }