Esempio n. 1
0
        public async Task TelnetConnect(string host, int port)
        {
            var endpoint     = new TelnetEndPoint(host, port);
            var connectionId = Context.ConnectionId;
            var connection   = new TelnetConnection(
                endpoint,
                data => Clients.Client(connectionId).telnetAddKeyCodes(data.Select(x => (int)x).ToArray()),
                () => Clients.Client(connectionId).telnetDisconnected());

            if (telnetConnections.TryAdd(connectionId, connection))
            {
                await connection.ConnectAndReceiveData();
            }
        }
Esempio n. 2
0
        private void WriteEscapeSequence(TelnetConnection telnetConnection, params byte[] values)
        {
            var fullEscapeSequence = new byte[values.Length + 2];

            fullEscapeSequence[0] = 0x1b;
            fullEscapeSequence[1] = 0x5b;

            for (int i = 0; i < values.Length; i++)
            {
                fullEscapeSequence[i + 2] = values[0];
            }

            telnetConnection.Write(fullEscapeSequence);
        }