Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //tc tcp клиент
- tempText = tc.Read().Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList();
- File.WriteAllLines("temp.txt",allLinesText);
- public string Read()
- {
- if (!tcpSocket.Connected) return null;
- StringBuilder sb = new StringBuilder();
- do
- {
- ParseTelnet(sb);
- Thread.Sleep(Sleeptime);
- } while (tcpSocket.Available > 0);
- return sb.ToString();
- }
- void ParseTelnet(StringBuilder sb)
- {
- while (tcpSocket.Available > 0)
- {
- int input = tcpSocket.GetStream().ReadByte();
- switch (input)
- {
- case -1:
- break;
- case (int)Verbs.IAC:
- // interpret as command
- int inputverb = tcpSocket.GetStream().ReadByte();
- if (inputverb == -1) break;
- switch (inputverb)
- {
- case (int)Verbs.IAC:
- //literal IAC = 255 escaped, so append char 255 to string
- sb.Append(inputverb);
- break;
- case (int)Verbs.DO:
- case (int)Verbs.DONT:
- case (int)Verbs.WILL:
- case (int)Verbs.WONT:
- // reply to all commands with "WONT", unless it is SGA (suppres go ahead)
- int inputoption = tcpSocket.GetStream().ReadByte();
- if (inputoption == -1) break;
- tcpSocket.GetStream().WriteByte((byte)Verbs.IAC);
- if (inputoption == (int)Options.SGA)
- tcpSocket.GetStream().WriteByte(inputverb == (int)Verbs.DO ? (byte)Verbs.WILL : (byte)Verbs.DO);
- else
- tcpSocket.GetStream().WriteByte(inputverb == (int)Verbs.DO ? (byte)Verbs.WONT : (byte)Verbs.DONT);
- tcpSocket.GetStream().WriteByte((byte)inputoption);
- break;
- default:
- break;
- }
- break;
- default:
- sb.Append((char)input);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment