Hallo stagetwo,
ich habe ein Problem & zwar versuche ich eine verbidung zum root zubekommen , bzw. ihm Daten zusenden.
Der aufbau klappt nur er bekommt nicht alle daten.
Sofern ich das localhost teste bekomme ich Username & Password.
Ist die Server.exe (die es empfängt) auf dem root an , empfange ich nur Username.
Server
Code
- static void Main(string[] args)
- {
- int port = 20000;
- IPAddress ipAddress = IPAddress.Any;
- TcpListener listener = new TcpListener(ipAddress, port);
- listener.Start();
- Console.WriteLine("Server is running");
- Console.WriteLine("Listening on port " + port);
- Console.WriteLine("Ready, the users can connect now !");
- while (true)
- {
- Socket s = listener.AcceptSocket();
- Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
- byte[] b = new byte[65535];
- int k = s.Receive(b);
- Console.WriteLine("Received:");
- for (int i = 0; i < k; i++)
- Console.Write(Convert.ToChar(b[i]));
- ASCIIEncoding enc = new ASCIIEncoding();
- s.Send(enc.GetBytes("Server pinged you back !"));
- Console.WriteLine("\n");
- s.Close();
- //meineMethode("Test");
- }
- }
Client:
Code
- public void Login(String username, String password)
- {
- if (textBox1.Text != "")
- {
- if (textBox2.Text != "")
- {
- TcpClient tcpclnt = new TcpClient();
- tcpclnt.Connect("127.0.0.1", 20000); // --
- string new_username = "@U: " + username + "\r\n";
- string new_password = "@P: " + password;
- Stream stm = tcpclnt.GetStream();
- ASCIIEncoding asen = new ASCIIEncoding();
- byte[] ba = asen.GetBytes(new_username);
- stm.Write(ba, 0, ba.Length);
- byte[] bb = new byte[100];
- byte[] bc = asen.GetBytes(new_password);
- stm.Write(bc, 0, bc.Length);
- String responseData = String.Empty;
- byte[] bl = new Byte[256];
- // Read the first batch of the TcpServer response bytes.
- Int32 bytes = stm.Read(bl, 0, bl.Length);
- responseData = System.Text.Encoding.ASCII.GetString(bl, 0, bytes);
- //Console.WriteLine("Received: {0}", responseData);
- //MessageBox.Show(responseData,"Received:");
- if(responseData == "Server pinged you back !")
- {
- state.Text = "Connected to the Server.";
- }
- tcpclnt.Close();
- }
- else
- {
- MessageBox.Show("Please enter a Password.", "Error 2",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else
- {
- MessageBox.Show("Please enter a Username.", "Error 1",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }