I am writing a (hopefully simple) console app to send commands to an audio device running telnet. These commands allow me to alter the state of DSP components contained within it, for example: ToneGen set mute true
.
Where I am having trouble is the telnet handshake, I understand that there are a number of commands sent from the Telnet Server to the client and that the client needs to respond to these in order to successfully negotiate the start of the session. I just don't know to send the correct commands. Below is my some what unsuccessful attempt.
Here is the code I have so far:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace telnetTest
{
class Program
{
static void Main(string[] args)
{
IPAddress address = IPAddress.Parse("192.168.10.101");
int port = 23;
IPEndPoint endpoint = new IPEndPoint(address, port);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Console.WriteLine("Establishing Connection to {0}", address);
s.Connect(endpoint);
byte[] Bytes = Encoding.ASCII.GetBytes("0xFC\0xFC\0XFC");
s.Send(Bytes);
byte[] buffer = new byte[50];
s.Receive(buffer);
Console.WriteLine(Encoding.ASCII.GetString(buffer));
Console.ReadKey();
}
}
}
The output from the code is as follows:
Establishing Connection to 192.168.10.101
??↑?? ??#??'??$
So I think I have two core issues here:
1) How to detect the handshake request from the audio device 2) How to send the appropriate response.
Any help would be greatly appreciated.
UPDATE 1
byte[] buffer = new byte[1024];
int vari = s.Receive(buffer);
string hex1 = vari.ToString("X");
Console.WriteLine(hex1);
After connecting hex1 returns a value of 15
UPDATE 2
Console.WriteLine("Sending Bytes");
byte[] Bytes1 = Encoding.ASCII.GetBytes("0xFF 0xFC 0x18 0xFF 0xFD 0x20 0xFF 0xFC 0x23 0xFF 0xFD 0x27 0xFF 0xFC 0x24 \n");
s.Send(Bytes1);
After the above code I am looking for the next response from the server by using the the following code,
byte[] buffer2 = new byte[1024];
int byteCount2 = s.Receive(buffer2);
Console.WriteLine(byteCount2 + " Bytes Found");
All I am seeing in the console is the Phrase "Sending Bytes" so it appears that Bytes1
is not being sent and there are no further response bytes to read.