示例#1
0
        /// <summary>
        /// Accepts connections and spawns thread to handle them
        /// </summary>
        private void AcceptConnections()
        {
            Socket socket = null;

            while (true)
            {
                // Accepts a connection on socket
                try
                {
                    socket = sock.Accept();
                }
                catch (Exception e)
                {
                    e.Message.ToString();
                }

                // create and setup socket state saver
                SocketState sockState = new SocketState();
                sockState.clientState.serverIPAddress1 = IPAddress.Parse(endPoint1);
                sockState.clientState.messageCount     = msgCount;
                sockState.clientState.pace             = pace;
                sockState.sock = socket;
                sockState.clientState.clientSock = socket;

                // set up the client socket
                ClientRun cr = new ClientRun();
                sockState.clientState.serverSock = cr.SetClientSocket(sockState.clientState);
                //Socket endPointSocket = cr.SetClientSocket(sockState.clientState);

                // start the timer
                sockState.stpWatch.Start();

                // Spawn thread and listen on endpoint connection
                sockState.clientState.serverThread = new Thread(delegate()
                {
                    cr.ClientReceive(sockState.clientState);
                });
                sockState.clientState.serverThread.Start();

                // Spawns thread and starts ConnectionHandler function
                sockState.thread = new Thread(delegate()
                {
                    ConnectionHandler(sockState);
                });
                sockState.thread.IsBackground = true;
                sockState.thread.Start();
            }
        }
示例#2
0
        /// <summary>
        /// Processes the sending funcitons of the server.
        /// This function will process messages then send
        /// them to alternate endpoint server.
        /// </summary>
        /// <param name="sockState">
        /// SocketState state saver object
        /// </param>
        private void SendFunction(SocketState sockState, byte[] messageBuffer)
        {
            try
            {
                byte[] processedMessage;
                // Have processed client message
                // need to forward this to the endpoint
                // on another socket
                ResponseBuilder rb = new ResponseBuilder();
                //sockState.clientState.processedMessage = rb.Response(sockState);
                processedMessage = rb.Response(sockState, messageBuffer);

                lock (proccessedLbAdd)
                {
                    // Add the processed message to the logbuilder
                    //sockState.clientState.lb.processedMessages.Add(sockState.clientState.processedMessage);
                    sockState.clientState.lb.processedMessages.Add(processedMessage);
                }

                // pass message to endpoint
                ClientRun cr = new ClientRun();
                Thread clientSendThread = new Thread(delegate()
                    {
                        cr.ClientSend(sockState.clientState, processedMessage);
                    });
                clientSendThread.Start();

                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //Thread reRoute = new Thread(delegate()
                //{
                //    cr.RouteMessage(sockState.clientState, processedMessage);
                //});
                //reRoute.Start();
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                //lock (sockState.clientState.clientSendLock)
                //{
                //    // Send message back to the client
                //    //sockState.sock.Send(sockState.clientState.processedMessage);
                //    sockState.sock.Send(processedMessage);
                //}
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
            }
            catch (Exception e)
            {
                e.ToString();
                System.Windows.Forms.MessageBox.Show("ServerRun.SendFunction\r\n" + e.Message.ToString());
            }
        }
示例#3
0
        /// <summary>
        /// Accepts connections and spawns thread to handle them
        /// </summary>
        private void AcceptConnections()
        {
            Socket socket = null;

            while (true)
            {
                // Accepts a connection on socket
                try
                {
                    socket = sock.Accept();
                }
                catch (Exception e)
                {
                    e.Message.ToString();
                }

                // create and setup socket state saver
                SocketState sockState = new SocketState();
                sockState.clientState.serverIPAddress1 = IPAddress.Parse(endPoint1);
                sockState.clientState.messageCount = msgCount;
                sockState.clientState.pace = pace;
                sockState.sock = socket;
                sockState.clientState.clientSock = socket;

                // set up the client socket
                ClientRun cr = new ClientRun();
                sockState.clientState.serverSock = cr.SetClientSocket(sockState.clientState);
                //Socket endPointSocket = cr.SetClientSocket(sockState.clientState);

                // start the timer
                sockState.stpWatch.Start();

                // Spawn thread and listen on endpoint connection
                sockState.clientState.serverThread = new Thread(delegate()
                    {
                        cr.ClientReceive(sockState.clientState);
                    });
                sockState.clientState.serverThread.Start();

                // Spawns thread and starts ConnectionHandler function
                sockState.thread = new Thread(delegate()
                {
                    ConnectionHandler(sockState);
                });
                sockState.thread.IsBackground = true;
                sockState.thread.Start();
            }
        }
示例#4
0
        /// <summary>
        /// Processes the sending funcitons of the server.
        /// This function will process messages then send
        /// them to alternate endpoint server.
        /// </summary>
        /// <param name="sockState">
        /// SocketState state saver object
        /// </param>
        private void SendFunction(SocketState sockState, byte[] messageBuffer)
        {
            try
            {
                byte[] processedMessage;
                // Have processed client message
                // need to forward this to the endpoint
                // on another socket
                ResponseBuilder rb = new ResponseBuilder();
                //sockState.clientState.processedMessage = rb.Response(sockState);
                processedMessage = rb.Response(sockState, messageBuffer);

                lock (proccessedLbAdd)
                {
                    // Add the processed message to the logbuilder
                    //sockState.clientState.lb.processedMessages.Add(sockState.clientState.processedMessage);
                    sockState.clientState.lb.processedMessages.Add(processedMessage);
                }



                // pass message to endpoint
                ClientRun cr = new ClientRun();
                Thread    clientSendThread = new Thread(delegate()
                {
                    cr.ClientSend(sockState.clientState, processedMessage);
                });
                clientSendThread.Start();



                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //Thread reRoute = new Thread(delegate()
                //{
                //    cr.RouteMessage(sockState.clientState, processedMessage);
                //});
                //reRoute.Start();
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                //lock (sockState.clientState.clientSendLock)
                //{
                //    // Send message back to the client
                //    //sockState.sock.Send(sockState.clientState.processedMessage);
                //    sockState.sock.Send(processedMessage);
                //}
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
                //-========================================
                // =---------------------------------------
            }
            catch (Exception e)
            {
                e.ToString();
                System.Windows.Forms.MessageBox.Show("ServerRun.SendFunction\r\n" + e.Message.ToString());
            }
        }