コード例 #1
0
        private void doChat()
        {
            int requestCount = 0;
            byte[] bytesFrom;
            string dataFromClient = null;
            Byte[] sendBytes = null;
            string serverResponse = null;
            string rCount = null;
            requestCount = 0;

            while ((true))
            {
                try
                {
                    requestCount = requestCount + 1;
                    NetworkStream networkStream = clientSocket.GetStream();
                    bytesFrom =  new byte[(int)clientSocket.ReceiveBufferSize];
                    networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                    dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);

                    Console.WriteLine(dataFromClient.Substring(0,100));

                    /**Anfrage*/
                    dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
                    //Encrypt String
                    MessageBuilder MB = new MessageBuilder();
                    String[] Request = MB.DeBuild(dataFromClient);
                    RequestHandler RH = new RequestHandler();
                    String[] ResponseArray = RH.handleMe(Request);

                    rCount = Convert.ToString(requestCount);

                    /**Antwort*/
                    //Crypt String
                    serverResponse = MB.Build(ResponseArray);

                    sendBytes = Encoding.ASCII.GetBytes(serverResponse);
                    networkStream.Write(sendBytes, 0, sendBytes.Length);
                    networkStream.Flush();

                    Console.WriteLine(serverResponse);

                    clientSocket.Close();
                    break;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(" >> " + ex.ToString());
                }
            }
        }
コード例 #2
0
        public void Start(IPAddress ipAddress, int port, string contentPath)
        {
            try
            {
                InitializeSocket(ipAddress, port, contentPath);
            }
            catch
            {
                Console.WriteLine("Error in creating server socket");
                Console.ReadLine();

            }
            while (_running)
            {
                var requestHandler = new RequestHandler(_serverSocket, contentPath);
                requestHandler.AcceptRequest();
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: JGDoerrer/KreativerName
 private static void ClientBytesRecieved(Client client, Packet packet)
 {
     RequestHandler.HandleRequest(client, packet);
 }