I have added the data analyzer routine to the TelnetServerFactory.cs
file and it is working fine with PuTTY. The PuTTY is now able to automatically detect the LocalEcho settings, so I don't need to force it off manually. I believe, this will help with KEA emulator as well.
Update the DirectSocket.Send()
method in the TelnetServerFactory.cs
file like this:
public int Send(byte[] buffer, int offset, int count, SocketFlags socketFlags)
{
int idx = IndexOf(WONT_ECHO, buffer, offset, count);
if (idx >= 0)
buffer[idx + 1] = 0xFB;
return _inner.Send(buffer, offset, count, socketFlags);
}
private int IndexOf(byte[] value, byte[] buffer, int offset, int count)
{
int maxOffset = offset + count;
while (count >= value.Length)
{
int idx = Array.IndexOf(buffer, value[0], offset, count);
if (idx < 0)
return -1;
bool found = IsValueAt_SkipFirst(value, buffer, idx, maxOffset);
if (found)
return idx;
int skip = idx + 1 - offset;
offset += skip;
count -= skip;
}
return -1;
}
private bool IsValueAt_SkipFirst(byte[] value, byte[] buffer, int idx, int maxIdx)
{
idx++;
for (int i = 1; i < value.Length; i++, idx++)
{
if (idx >= maxIdx || value[i] != buffer[idx])
return false;
}
return true;
}
And also define this:
private static readonly byte[] WONT_ECHO = { 0xFF, 0xFC, 0x01 };