コード例 #1
0
        private void ServerThreadStart()
        {
            Socket            clientSocket   = null;
            HSMSocketListener socketListener = null;

            while (!stopServer)
            {
                try
                {
                    DBClient db = new DBClient("127.0.0.1", 1433);
                    db.Connect();
                    // Wait and accept client requests
                    clientSocket = server.AcceptSocket();

                    // Create a SocketListener object for the client.
                    socketListener          = new HSMSocketListener(clientSocket);
                    socketListener.DBClient = db;

                    // Add the socket listener to an array list in a thread afe fashion.
                    lock (socketListenersList)
                    {
                        socketListenersList.Add(socketListener);
                    }

                    // Start a communicating with the client in a different thread.
                    socketListener.StartSocketListener();
                }
                catch (SocketException se)
                {
                    stopServer = true;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// This is where the message is sent to the HSM and the response is returned back
        /// </summary>
        /// <param name="byteBuffer"></param>
        /// <param name="size"></param>
        private void ProcessRequest(Byte[] byteBuffer, int size)
        {
            string data = Encoding.ASCII.GetString(byteBuffer, 0, size);


            Trace.TraceInformation(data);

            try
            {
                //TODO: this part is for HSM
                //Process the request and send back

                //ThalesHsm hsm = new ThalesHsm();
                //string output = hsm.SendProxyCommand(data);
                //Byte[] sendBytes = Encoding.ASCII.GetBytes(output);
                //m_clientSocket.Send(sendBytes);


                //DBClient db = new DBClient("127.0.0.1", 8583);
                Byte[] sendBytes = DBClient.SendProxyCommand(data);
                m_clientSocket.Send(sendBytes);
            }
            catch (SocketException se)
            {
                Trace.TraceInformation(se.ToString());
            }
        }