I try to connect to my TeamSpeak 3 server using telnet in a C# application.
By the way, im not very experienced using telnet ^^', so I showed up the telnet Code at the Site https://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient(VS.80).aspx
The following code should:
- connect to the teamspeak server
- send the password and read out the welcome message
send the command "help" and read out the help Message
string command = "help"; // creates new TCP client TcpClient client = new TcpClient(adress, port); // get client stream NetworkStream stream = client.GetStream(); // send Password Byte[] data = System.Text.Encoding.ASCII.GetBytes(password); stream.Write(data, 0, data.Length); data = new Byte[256]; Thread.Sleep(200); Int32 bytes = stream.Read(data, 0, data.Length); String responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); Console.WriteLine(responseData); // send the given command Byte[] data2 = System.Text.Encoding.ASCII.GetBytes(command); stream.Write(data2, 0, data2.Length); data2 = new Byte[2560]; Thread.Sleep(200); Int32 bytes2 = stream.Read(data2, 0, data2.Length); String responseData2 = System.Text.Encoding.ASCII.GetString(data2, 0, bytes2); Console.WriteLine(responseData2); // end stream and client stream.Close(); client.Close();
The first query works as it should and writes the welcome message into the Console. But at Int32 bytes2 = stream.Read(data2, 0, data2.Length);
in the seccond query the application stops without giving back any exeption.
Can anyone explain why the I cant read out the Help Message?