This code has been moved to a GitHub repository with the corresponding license. https://github.com/UngarMax/TelnetServer
-
-
Save robertripoll/6394321573dc0791dff9 to your computer and use it in GitHub Desktop.
You can use String.Trim
Can you write a Telnet Client in C# for this code ? (shouldn't just for this server)
@BruceGreene I just made a revision that contains fixed various issues which happened when the client removed a character with backspace and so on.
TryGetValue won't raise an exception when the key is not found, it will return false:
private TelnetServerClient getClientBySocket(Socket clientSocket)
{
TelnetServerClient c;
try
{
clients.TryGetValue(clientSocket, out c);
}
catch
{
c = null;
}
return c;
}
---
private TelnetServerClient getClientBySocket(Socket clientSocket)
{
TelnetServerClient c;
if(clients.TryGetValue(clientSocket, out c))
return c;
else
return null;
}
C# and camelCase... :*-(
@jvanlangen That's absolutely right TryGetValue, returns a boolean to specify whether the value was found by the passed key. I just made a revision to fix that.
+1 Nice code, thanks. What about to convert it to a small repo? Also, I agree with @jvanlangen that the methods starting with lower case are not according to C# standard.
Also from my cygwin client I had to change:
- line end add condition:
|| (data[0] == 0x0D && data[1] == 0x00))
- backspace is 0x7F:
if (data[0] == 0x08 || data[0] == 0x7F)
hi, i want ubiquit system reboot one click by telnetserver. can you tell me how make it c# code?
Hi. Thanks for the code. Would you mind creating a repo and attach a license to it so that people can use it without fear? Appreciated!
This gist has been moved to a GitHub repository: https://github.com/UngarMax/TelnetServer
Hi. Thanks for the code. Would you mind creating a repo and attach a license to it so that people can use it without fear? Appreciated!
@ychen5osram Done! https://github.com/UngarMax/TelnetServer
Hi. Thanks for the code. Would you mind creating a repo and attach a license to it so that people can use it without fear? Appreciated!
@ychen5osram Done! https://github.com/UngarMax/TelnetServer
thx a lot!
Very helpful, especially the support for multiple clients. Thanks!
Works great with the Windows Telnet client, but machine clients will send "command\r\n" all together, so for my application I need to check for "\r\n" at the end of the data...
if (received >= 2 && data[received - 2] == 0x0D && data[received - 1] == 0x0A)
{
string currentCommand = client.commandIssued;
if (received > 2)
currentCommand += Encoding.ASCII.GetString(data, 0, received - 2);