35a0e5fb87c3176e2081578a99bb87d9.ppt
- Количество слайдов: 38
ENET with MAC controller MS_u. C / fue 1 / V 11 2 - 1 Programming Microcontroller ENET (Ethernet) peripheral with MAC (Media Access Control) controller ARM 966 E CORE w/DSP 96 MHz DMA PFQ BC INTR Cntl CLK Cntl LVD BOD PLL ADC RTC 64 K or 96 K Byte SRAM 256 K or 512 K Byte Burst Flash 32 K Byte Burst Flash OTP JTAG ETM 9 Mem TIM SPI I 2 C Enet MAC USB 2. 0 FS CAN 2. 0 B GPIO EXT. Bus UART
MS_u. C / fue 1 / V 11 16. 03. 2018 The classical web applications z Standard way of web communication y Browser as web client y Web server with data base z The purpose of web application y Represent the data of the server on the client y Save the input of the client on the server z Example of web applications y Query the SBB timetable y Buy books y Download information about a company 2
MS_u. C / fue 1 / V 11 16. 03. 2018 Static web pages z Static web pages are displayed without further processing y HTML, XML y CSS y Plug-Ins (Multimedia) 3
MS_u. C / fue 1 / V 11 16. 03. 2018 Dynamic web pages z Client-side dynamic execution y Script languages (Java. Script) y Execution of Programs (Applet) z Server-side dynamic execution y Script languages (Perl & PHP) y Execution of Programs (Servlet) 4
MS_u. C / fue 1 / V 11 16. 03. 2018 Client-side dynamic execution z Typical applications y Context depending menus, input validation & calculation with formula 5
MS_u. C / fue 1 / V 11 16. 03. 2018 Server-side dynamic execution z Typical applications y Creation of individual user web pages 6
MS_u. C / fue 1 / V 11 16. 03. 2018 Programming languages for Internet z Script languages y Client-side script languages x. Java. Script, VBSkript & Jscript y Server-side script languages x. Perl & PHP z High-level languages y C, C++, C#, Visual Basic or Java 7
16. 03. Comparison between Script & High-level Languages MS_u. C / fue 1 / V 11 2018 Script programming language Task High-level programming language client Small help programs, plug-in server dynamic generation of web pages Execution Script are executed by an interpreter Compiler generates a byte (intermediate) or an executable code Learning time Small until medium Medium until high Development environment Text editor or script-tools Development environment: JDK or Visual Studio Integration into XHTML pages Integration directly into XHTML pages XHTML page contains the reference for the plug-in Limited access to hard disk, memory & LAN for Java. Script. No direct access to hard disk, memory & LAN interface for Java applets. client Security Full access with VBScript server Full access to databases, I / O system, etc. 8
16. 03. 2018 MS_u. C / fue 1 / V 11 Languages & technologies for web site development sun Standard Microsoft HTML, XHTML & CSS Static XML Client VBScript Java. Script Jscript Java. Script Dynamic Java Applet . net Server JSP (Java Server Page) Java Servlet CGI / Perl PHP (Pers. Homepage) More complicate program (C/C++ etc. ) ASP (Active Server Page). net 9
MS_u. C / fue 1 / V 11 16. 03. 2018 Embedded web server z Application examples for the embedded word y Machines, automation etc. which should be accessible through Internet z Purpose of the “Embedded web server” y Remote maintenance (diagnostic, setting the parameters) y Alarming y Configuration 10
ISO/OSI Model for the Client-Server communication 16. 03. MS_u. C / fue 1 / V 11 2018 Transport Network Data link Physical 11
MS_u. C / fue 1 / V 11 16. 03. 2018 Principles of the Client-Server communication 12
MS_u. C / fue 1 / V 11 16. 03. 2018 Socket (Buchse / prise) z Socket is an endpoint for communication between two machines y IP Address y Protocol (TCP or UDP) y Port number z General procedure for exchanging data y Build a connection using two sockets y Exchange of data y Close the connection 13
MS_u. C / fue 1 / V 11 16. 03. 2018 TCP based application z TCP is a connection-oriented transport protocol y Transmission Control Protocol z Creating the TCP connection y First, start the server y Next the client must connect himself to the server y Finally the data can be exchanged in both directions 14
MS_u. C / fue 1 / V 11 16. 03. 2018 15
MS_u. C / fue 1 / V 11 16. 03. 2018 socket() z socket() creates a TCP or UDP socket y Server Socket SS on the server y Client Socket CS on the client z Specification of the used protocol (TCP or UDP) 16
MS_u. C / fue 1 / V 11 16. 03. 2018 bind() z bind() binds the socket with a local protocol address y IP address & port number z bind() is only uses by the server 17
MS_u. C / fue 1 / V 11 16. 03. 2018 listen() z listen() sets the server in a listening mode z Maximum number of connections that will be processed simultaneously 18
MS_u. C / fue 1 / V 11 16. 03. 2018 accept() z accept() enables the Server to accept a connection from a client y Full queue (backlog) x. Next connection request from the queue y Empty queue x. New connection request from a client 19
MS_u. C / fue 1 / V 11 16. 03. 2018 connect() z connect() enables the client to build a connection with the server z Server socket creates a new socket (new. SS) y Dedicated line to the requested client 20
MS_u. C / fue 1 / V 11 16. 03. 2018 recv() and send() z The data are exchanged in both direction with recv() & send() 21
MS_u. C / fue 1 / V 11 16. 03. 2018 close() z After successful communication y The sockets new. SS & CS must be closed 22
UDP-based applications 16. 03. MS_u. C / fue 1 / V 11 2018 z UDP is minimal and non connection-oriented transport protocol y User Datagram Protocol 23
MS_u. C / fue 1 / V 11 16. 03. 2018 Socket programming in C z Programming of client and server applications in C y Application Programming Interface (API) functions of the TCP/IP- Stacks 24
MS_u. C / fue 1 / V 11 16. 03. 2018 Data structure for the protocol addresses (1) z Common data structure y struct sockaddr { unsigned short sa_family unsigned sa_data[14]; // Address family (AF_INET) /* Protocol-specific address information */ } z Data structure for AF_INET (Address Family Interactive Network System) y struct sockaddr_in { unsigend short sin_family unsigned short sin_port; struct in_addr sin_addr; } struct in_addr { NET_IP_ADDR s_addr; } // Protocol family (PF_INET) // Address port (16 bits) // IP address (32 bits) 25
MS_u. C / fue 1 / V 11 16. 03. 2018 Data structure for the protocol addresses (2) 26
MS_u. C / fue 1 / V 11 16. 03. 2018 Help function z Transmission of sockaddr & sockaddr_in in big endian y Network byte order z Conversion from the “host byte order” into “network byte order” y uint 32_t htonl (uint 32_t hostlong); y uint 16_t htons (uint 32_t hostshort); 27
MS_u. C / fue 1 / V 11 16. 03. 2018 socket() z Prototype y int socket (int domain, int type, int protocol); z Argument y domain x. Application domain of the socket (PF_INET) y type x. Behavior of the socket (SOCK_STREAM or SOCK_DGRAM) y protocol x. IPPROTO_TCP or IPPROTO_UDP z Result y Success: Socket-ID y Error: -1 28
MS_u. C / fue 1 / V 11 16. 03. 2018 bind() z Prototype y int bind (int sock_id, struct sockaddr *addr, int addrlen); z Argument y sock_id x. Result of socket() y addr x. Information about Port number & IP address y addrlen x. Size of addr z Result y Success: 0 y Error: -1 29
MS_u. C / fue 1 / V 11 16. 03. 2018 listen() z Prototype y int listen (int sock_id, int backlog); z Argument y sock_id x. Result of socket() y backlog x. Maximum waiting clients z Result y Success: 0 y Error: -1 30
MS_u. C / fue 1 / V 11 16. 03. 2018 connect() z Prototype y int connect (int sock_id, struct sockaddr *addr, int addrlen); z Argument y sock_id x. Result of socket() y addr x. Information about Port number & IP address of the server to connect y addrlen x. Size of addr z Result y Success: 0 y Error: -1 31
MS_u. C / fue 1 / V 11 16. 03. 2018 accept() z Prototype y int accept (int sock_id, struct sockaddr *addr_remote, int *addrlen_remote); z Argument y sock_id x. Result of socket() y addr_remote x. Information about Port number & IP address of the client y addrlen_remote x. Size of addr_remote z Result y Success: new socket ID y Error: -1 32
MS_u. C / fue 1 / V 11 16. 03. 2018 recv() z Prototype y int recv (int new. Sock_id, void *buf, int *buf_len, int flags); z Argument y new. Sock_id or sock_id x. Result of accept() on server side or socket() on client side y buf x. Buffer for the received data y buf_len x. Length of buf y flags x. Receive option: can be set to zero z Result y Success: Number of received bytes y Error: -1 33
MS_u. C / fue 1 / V 11 16. 03. 2018 send() z Prototype y int send (int new. Sock_id, void *data, int datalen, int flags); z Argument y new. Sock_id or sock_id x. Result of accept() on server side or socket() on client side y data x. The data to transmit y datalen x. The length of the data to transmit y flags x. Transmit option: can be set to zero z Result y Success: Number of transmitted bytes y Error: -1 34
MS_u. C / fue 1 / V 11 16. 03. 2018 Programming in Java z Class Socket y Socket (String host, int port); z Stream Classes for sending or receiving the data y Buffered. Reader y Input. Stream. Reader (ASCII unicode) y Input. Stream (ASCII) y Print. Stream (unicode ASCII) y Output. Stream (ASCII) 35
MS_u. C / fue 1 / V 11 16. 03. 2018 Generating a client socket in Java z public void open. Socket(){ try{ // replace parameters with real values sock = new Socket(Server_Address, Port); // Send without delay sock. set. Tcp. No. Delay(true); input. Stream = sock. get. Input. Stream(); buffered. Reader = new Buffered. Reader new Input. Stream. Reader(in. Stream)); output. Stream = sock. get. Output. Stream(); print. Stream = new Print. Stream(out. Stream, true); } catch (Socket. Exception e){ // error handling } catch (IOException e){ // error handling } } 36
MS_u. C / fue 1 / V 11 16. 03. 2018 Closing the socket and the data stream z public void close. Socket(){ try { input. Stream. close(); output. Stream. close(); sock. close(); } catch (IOException e){ // error handling } } 37
MS_u. C / fue 1 / V 11 16. 03. 2018 Transmitting & Receiving the data z public void send. Data(String data){ print. Stream. print(data); } z public void get. Data(){ String data; try { data = buffered. Reader. read. Line(); // process data } catch (IOException e){ // error handling } } 38