telnet Client User Interface for Accessing MX7cK s push buttons and LEDs. Template for P1.3 1
Motivation for Using telnet We have written a ToUpper server that uses TCP and runs on the TCP/IP stack of the MX7ck board. We need a TCP client to connect to this server in order to test the server. Instead of writing a TCP client at this time, we will use a given telnet client program, which is provided by the OS. In basic telnet, the peer-to-peer communications protocol is straight ASCII text sent over a TCP connection. The telnet client program does not define a carrier protocol, to carry the straight text. Therefore, it is not necessary to connect to a telnet server. We will connect the telnet client to our TCP server, directly, and thus have a means of testing it. 2
What is telnet? telnet is a network based client-server program that is available to run on many popular operating systems, such as Windows, Mac, and Unix. telnet runs on the application layer. Unlike http and other application layer protocols, telnet is a complete program that does not need a network based program to run on top of it. Typically, a client user runs a telnet client program to connect to a telnet server to gain access to the resources of the server host computer. Network Based Program Application Layer (HTTP, telnet (client), others ) API Transport Layer (TCP, UDP, ) API Network Layer (IP, ) API Link Layer (Ethernet, WiFi, ) Network Based Program Application Layer (HTTP, telnet (server), others ) API Transport Layer (TCP, UDP, ) API Network Layer (IP, ) API Link Layer (Ethernet, WiFi, ) On Client Host Network On Server Host 3
What is telnet? A telnet client program runs on a computer terminal, typically a terminal that supports the VT100 standard. You run the program by typing its name in the terminal. A telnet server runs in the background on the Application Layer of the TCP/IP stack. Sometimes, a telnet server may have a user interface on the server host machine, but normally, there is no user interface to a telnet server. A client telnet program can connect to a telnet server on port 23. Telnet server runs in background On Client Host Network On Server Host 192.168.1.49 4
telnet is a Session Layer Protocol telnet is also known as a session layer protocol The session layer, which is built-in to telnet programs, provides the mechanism for opening, closing and managing a TCP session between telnet client and server programs. This means users of telnet do not write code for opening, closing and managing a TCP session; this code is already part of the telnet program. A telnet client user sends text messages to a telnet server, and the server responses are simple text messages. 5
telnet Defines No Carrier Protocol The basic telnet protocol defines no carrier protocol. It sends/receives messages using raw text format User application protocol language is transmitted in raw text format. I.e., user messages are sent from the client program to the server in raw format, and a carrier is not used. A telnet client and server use TCP for their connection This implies that a telnet client program does not need to connect with a telnet server running at port 23: A telnet client can successfully connect to a raw-text TCP server at any available port. In Project P1.3, our telnet server will be a raw-text TCP server whose port number is 7777. 6
Example of HTTP Session Here is an example of what a client web browser would send to a web server: GET /index.html HTTP/1.1 host: http://ece.eng.umanitoba.ca/undergraduate/ece3740/ Response sent by web server to web browser (client): HTTP/1.1 200 OK Date: Wed, 30 Sep 2015 10:08:00 GMT //other server information <html> <head> <title>......lots of HTML code here that defines the 3740 web page you see </body></html> Note: the carrier protocol in green (HTTP) and the application protocol language in blue (HTML). Note: that the server sends the user interface to the client web browser. Note: there could be also a user layer protocol on top of html. The user protocol would define a users interaction with the server via the html web page s objects, such as textbox, buttons, etc. 7
Example of telnet Session The following shows part of a user protocol on top of telnet. A user of a telnet program (telnet client) sends a message to the code within a telnet server, and a response received: Sent by user of telnet client to telnet server: Hello telnet server! Response sent by telnet server to telnet client: Hello telnet client! Notice there is no carrier protocol, but just a user layer protocol language in blue. 8
Examples given: a telnet server can provide services to: Access OS commands for manipulating files on the server s computer, like pwd, cd, copy, move, and delete. Configure devices connected to the server s machine Set bit rate of a COM port Enable different kinds of modulation and forward error correction for a modulator. The services a telnet server offers is application dependant, i.e., the services are whatever the designers of the telnet server decided to program into the server. For example, in our course, the telnet server is to provide services to: Rotate the LEDs on the MX7cK Get the status of the switches, LEDs, and sensors Turn on/off LEDs. Note: due to computer security concerns, many organizations no longer offer the basic telnet programs, since an adversary could gain access to a computer system relatively easily and cause damage or obtain confidential information. For example, should an adversary install a rogue TCP server on a host, then, it would be possible for the adversary to remotely connect to the server and proceed to cause damage to the host computer or download personal information. 9
telnet is a program that runs on a VT100 standard compatible terminal. The standard specifies a way to display and format the display or characters on a VT100 compatible computer terminal. Normally, a VT100 terminal software displays a sequence of ASCII characters that you send it, except for a special case: an Escape (ESC) character. When you send a message to a VT100 terminal that has the first character as the ANSI escape character ESC (1Bh), the VT100 software interprets the following characters of the message as codes for how to format the display or how to format a character for display. For example: 1B[2J // 1B is the hex encoded escape character; [2J means Clear the screen 10
For Text Attributes ANSI Description [0m Reset all attributes [1m Set bright attribute [2m Set dim attribute [4m Set underline attribute [5m Set blink attribute [7m Set reverse attribute [8m Set hidden attribute 11
Foreground Color (Text Color) ANSI Description [30m Set foreground to color #0 - black [31m Set foreground to color #1 - red [32m Set foreground to color #2 - green [33m Set foreground to color #3 - yellow [34m Set foreground to color #4 - blue [35m Set foreground to color #5 - magenta [36m Set foreground to color #6 - cyan [37m Set foreground to color #7 - white [39m Set default color as foreground color 12
Background Color ANSI Description [40m Set background to color #0 - black [41m Set background to color #1 - red [42m Set background to color #2 - green [43m Set background to color #3 - yellow [44m Set background to color #4 - blue [45m Set background to color #5 - magenta [46m Set background to color #6 - cyan [47m Set background to color #7 - white [49m Set default color as background color 13
For Editing Commands [P Delete character from cursor position [*P Delete * chars from cursor right [M Delete 1 line from cursor position [*M Delete * lines from cursor line down [J Erase screen from cursor to end [1J Erase beginning of screen to cursor [2J Erase entire screen but do not move cursor [K Erase line from cursor to end [1K Erase from beginning of line to cursor [2K Erase entire line but do not move cursor [L Insert 1 line from cursor position [*L Insert * lines from cursor position 14
General Codes Name Decimal Hex C-escape Description BEL 7 0x07 \a Terminal bell BS 8 0x08 \b Backspace HT 9 0x09 \t Horizontal TAB LF 10 0x0A \n Linefeed (newline) VT 11 0x0B \v Vertical TAB FF 12 0x0C \f Formfeed (also: New page NP) CR 13 0x0D \r Carriage return ESC 27 0x1B <none> Escape character DEL 127 0x7F <none> Delete character 15
P1.3: telnet Client User Interface Requirements Analysis Which component should create/manage the User Interface (UI) for the telnet client program: client or server? Note: normally, a program would create its own user interface, like PowerPoint writers created a Graphical User Interface (GUI). Some client-server applications offer an option that the server creates and manages the client user interface, such as in web browser/server and telnet client-server systems. Here are the alternatives with advantages (+) and disadvantages (-) Client + No need to transmit UI over the network. Any UI modification may require modification on all clients. Must have access to telnet client source code, or create your own (including managing TCP connections). Server Bandwidth for transmitting UI to each connected client. + Any UI modification requires modification on server only. + Simpler client. Choice: Server (for our app, the UI is not many bytes (simple text based UI), and so the required bandwidth is minimal) 16
What functions or capabilities should the UI provide? These are the requirements of the UI. Note: a requirement describes WHAT the system should do, while design is HOW the system implements a requirement. For example: Requirements: The client interface shall allow a user to input a command to rotate the LEDs to the left. (This is what the system should do.) The delay between shining each LED should be about 1s. (what to do.) Design The system uses a text based user interface, in which the 1 key causes the server to rotate the LEDs in the left direction. (How the system does the requirement.) A software delay function is used to implement the delay between switching LEDs on/off. (How the system does the requirement.) 17
Difference Between Requirements and Design Note: The requirement that states The client interface shall allow a user to input a command to rotate the LEDs to the left, does not specify how the software should implement this requirement: For examples: the implementation could be by: Voice command Graphical user interface menu item Command line interface text based command The command could be by typing rotate LEDs Left on the command line interface The command could be by typing 1 on the command line interface This provides flexibility to the designers. However, the chosen method must satisfy the requirement. 18
What are the Requirements? Homework 19
C Strings For Writing Control Codes Note: since our designs will be that the server will send the UI to the client, we need to write C source code on the server to send the UI to the client. When you use C s string functions, the arguments (i.e., the strings) will be formatted in ASCII. For example, 1 is sent as 0x31. This is fine for sending text messages, but we need to send the escape code, which should not be encoded in ASCII, and other formatting codes, encoded in ASCII, to the VT100 terminal. Consider the C-string: \x1b[2j \x1b[2j \x is the C-escape-x: \x informs the C-compiler that the following string 1B[2J should be interpreted as a Hex encoded byte, until a non-hex symbol, is encountered. At that point the remaining part of the string will be encoded in ASCII. \x1b[2j will be encoded as: 1B5B324A, where 1B is the Hex encoded byte of 1B, and 5B, 32, and 4A are the ASCII codes for [, 2, and J, respectively. Note that the [ character is the first non-hex symbol in the string, so 1B will be encoded as a Hex byte. 1B Hex code for escape: informs the terminal that the following is not a string to display, but it is a control code [2J 5B324A = Control code for Clear Screen 20
Menu 21
After user types 1 After user types d After user types s 22
case SM_DISPLAY_MENU: // Display the menu if(!tcpisconnected(mysocket)) return; int size=sizeof("\x1b[2j \x1b[37m \x1b[1m LED SERVER MENU\n\r1: Put your menu items and control codes here"); if((tcpisputready(mysocket)) < size) return; TCPPutArray(MySocket, (BYTE*)"\x1B[2J \x1b[37m \x1b[1m LED SERVER MENU\n\r1: Put your menu items and control codes here ", size); TCPFlush(MySocket); TCPServerState = SM_PROCESS; break; 23