Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.

Slides:



Advertisements
Similar presentations
Network Programming Week #1 J.P. Yoo
Advertisements

Echo server The client reads a line of text from its standard input and writes the line to the server The server reads the line from its network input.
Socket Programming 101 Vivek Ramachandran.
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
Socket Programming CS3320 Fall 2010.
Socket Programming. Basics Socket is an interface between application and network – Application creates a socket – Socket type dictates the style of communication.
CS 4700 / CS 5700 Network Fundamentals
CSE 333 – SECTION 8 Networking and sockets. Overview Network Sockets IP addresses and IP address structures in C/C++ DNS – Resolving DNS names Demos.
Taekyung Kim 0x410 ~ 0x International Standards Organization (ISO) is a multinational body dedicated to worldwide agreement on international.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
Windows Sockets Purpose Windows Sockets 2 (Winsock) enables programmers to create advanced internet, intranet, and other network-capable applications to.
Tutorial 8 Socket Programming
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
Introduction to Project 1 Web Client and Server Jan 2006.
Network Programming Tutorial #9 CPSC 261. A socket is one end of a virtual communication channel Provides network connectivity to any other socket anywhere.
Socket Programming. Introduction Sockets are a protocol independent method of creating a connection between processes. Sockets can be either – Connection.
Chapter 17 Networking Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William Stallings.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
LWIP TCP/IP Stack 김백규.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
 Wind River Systems, Inc Chapter - 13 Network Programming.
Chapter 2 Applications and Layered Architectures Sockets.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
CPSC 441 TUTORIAL – FEB 13, 2012 TA: RUITNG ZHOU UDP REVIEW.
1 Computer Networks An Introduction to Computer Networks University of Tehran Dept. of EE and Computer Engineering By: Dr. Nasser Yazdani Lecture 3: Sockets.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Chapter 27 Socket API Interface The interface between an application program and the communication protocols in an operating system is known as the Application.
Socket Programming Lab 1 1CS Computer Networks.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Part 4: Network Applications Client-server interaction, example applications.
Socket Programming.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
Socket Programming. Computer Science, FSU2 Interprocess Communication Within a single system – Pipes, FIFOs – Message Queues – Semaphores, Shared Memory.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Socket Abstraction and Interprocess Communication
Socket Programming in C
Socket Interface 1 Introduction 11 Socket address formats 2 API 12 13
Interprocess Communication
Transport layer API: Socket Programming
Socket Abstraction and Interprocess Communication
Socket Programming in C
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Socket Abstraction and Interprocess Communication
Interprocess Communication
Socket Abstraction and Interprocess Communication
Chapter 3 Socket API © Bobby Hoggard, Department of Computer Science, East Carolina University These slides may not be used or duplicated without permission.
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Inter-process Communication
Socket Programming(1/2)
Socket Abstraction and Inter-process Communication
Internet Networking recitation #8
Presentation transcript:

Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi

Computer Net Lab/Praktikum Datenverarbeitung 2 2 Inter process communication There are two possibilities when two processes want to exchange data. Either they communicate directly to each other (via a network) or they use a common storage system. Data exchange can be done by: –Files –Shared memory –Pipes – Sockets

Computer Net Lab/Praktikum Datenverarbeitung 2 3 Socket Properties A Socket is an end point of a communication connection between two objects (processes). –Sockets belong to an application. –Sockets are bound to a port number. –Sockets can be bound to all or to definite IP-Addresses of a computer. –Sockets are available as TCP, UDP and as RAW Variant.

Computer Net Lab/Praktikum Datenverarbeitung 2 4 Socket (History) Developed for communication of local processes. Implemented 1982 in BSD Unix 4.1c. In BSD Version 4.3 extension of this interface in order to allow communication over TCP/IP. First time only available under UNIX-Systems. Later some different Socket-libraries under windows were available. Microsoft set up a standard: „windows Sockets“= „WinSocks“

Computer Net Lab/Praktikum Datenverarbeitung 2 5 Sockets and Protocol hierarchy

Computer Net Lab/Praktikum Datenverarbeitung 2 6 Client-Server Communication Client : User of a service Server : Offers a service

Computer Net Lab/Praktikum Datenverarbeitung 2 7 Socket Programming with UDP UDP: Service is not reliable, no guarantee that transmitted data will reach the receiver. no “connection“ between client and server. No handshaking. Sender specifies receivers IP-Address and port number. The receiver must extract IP-Address and port number out of the senders datagram in order to be able to send data back to the sender.

Computer Net Lab/Praktikum Datenverarbeitung 2 8 Socket Programming with TCP TCP: reliable transfer of data from one point to the other. Handshake method. Distinguish between Server and Client Process. Server creates listen-Socket, which is listening on a well defined port. Client creates Client-Socket, with destination IP-Address and port of the server. If the client connects the server, the server creates an additional socket which is used for the further communication between client and server.

Computer Net Lab/Praktikum Datenverarbeitung 2 9 Sockets in RAW Mode Neither TCP nor UDP. Allows direct access to the network because it is possible to feed directly packages into the network Protocol can be selected (i.e. ICMP) or can be completely new implemented. Even the IP-Header must be developed for the latter case. Under Unix only the super user can use RAW-Sockets. A very good knowledge about network protocols is required.

Computer Net Lab/Praktikum Datenverarbeitung 2 10 Communication (TCP) Set up Socket end points Accept connection Data transfer Close connection Data transfer Open connection Bind socket to IP-Address and port number Listen for incoming connections

Computer Net Lab/Praktikum Datenverarbeitung 2 11 Communication (TCP) socket connect send recv socket bind listen accept fork socket connect send recv send asock1 asock2 process Client Server process

Computer Net Lab/Praktikum Datenverarbeitung 2 12 Functions for C-Programming Server und Client –Socket(...) –Send(...) –Recv(...) –Close(...) Only server –Bind (...) –Listen (...) –Accept (...) Only Client –Connect (...) Client

Computer Net Lab/Praktikum Datenverarbeitung 2 13 Function Socket descriptor = socket(protofamily, type, protocol) The procedure socket creates a new socket and returns an integer value as descriptor (Identifier and reference for the Socket-Object). As arguments (parameter) the protocol family, the communication type and the protocol are required.. Arguments: – protofamily defines Protocol family (TCP/IP, Unix,...) – type : communication type (connection oriented, without connection or raw) – protocol : only used in raw mode

Computer Net Lab/Praktikum Datenverarbeitung 2 14 Function Bind (Server) bind(socket, localaddr, addrlen) The procedure bind connects a new created socket to a network address and a port. Arguments: –Socket is the descriptor, which is returned by the function socket. – localaddr defines the local address of the socket (IP-Address and port) –The integer value addrlen contains the length of the used data structure.

Computer Net Lab/Praktikum Datenverarbeitung 2 15 Function Listen (Server) listen (int socket, int queuesize) This function is used in order to show that the server is ready for accepting incoming requests of clients. If the server is working on an other request, the incoming requests are placed in a waiting queue. Arguments: –Socket contains the descriptor, which is returned by the function Socket – queuesize is the maximum of requests which are accepted by the waiting queue. Further requests are rejected if the waiting queue is full.

Computer Net Lab/Praktikum Datenverarbeitung 2 16 Function Accept (server) newsock = accept(int socket, struct clientadress, int cadresslen) Reads the first connection request out of the queue. The process is blocked if no request exist. The function “ accept” creates a new socket data structure and return a new descriptor (newsock). By use of this “ newsock” the further communication with the client is made. Remark: The new socket does not use a new port. The incoming data are assigned to the right socket by use of the client address data (IP-Address, port). Arguments: –Socket contains the descriptor returned by the function socket. – clientadress is a data structure where the data (IP-Address, port number) of the requesting client are stored. – cadresslen is the length of the clientadress -Structure

Computer Net Lab/Praktikum Datenverarbeitung 2 17 Function Connect (Client) connect(int socket, struct serveradress, int sadresslen) Allows the client to start a connection request to the server. The function returns when the server has successfully finished his accept procedure. Arguments: – socket contains the descriptor – serveradress is data structure which specifies the IP-address and the port number of the desired server. If the connection request is successful the servers data are filled in this data structure. A new port is bind to the socket (like bind at the server). – sadresslen the length of the serveradress -structure

Computer Net Lab/Praktikum Datenverarbeitung 2 18 Functionen Send, Recv send( int socket, data, int length, unsigned int flags) recv( int socket,data, int length, unsigned int flags) By use of these functions we can send and receive data. The function “ recv ” blocks the process until the data are received. The result of these functions is in both cases the number of the transferred bytes. Arguments: – socket is the descriptor of the socket. – data is a pointer to the data structure where the sent/received data are stored. Length is the number of bytes. – flags contain information about special function for sending and receiving.

Computer Net Lab/Praktikum Datenverarbeitung 2 19 Function close close(int socket) The function „ close“ closes a socket which was before created by the function socket. Therefore this socket is not longer used by the system. If TCP is used, the queued data are transmitted before the socket is closed. If only the data transmission should be finished, the function shutdown can be used instead of the function „ close“.

Computer Net Lab/Praktikum Datenverarbeitung 2 20 Client-example in C int main(int argc, char *argv[]) { int s; struct sockaddr_in srv; char buffer[1024]; if (argc != 3) { fprintf(stderr, "usage: %s host port\n", argv[0]); return 1; } s = socket(AF_INET, SOCK_STREAM, 0); srv.sin_addr.s_addr = inet_addr(argv[1]); srv.sin_port = htons( (unsigned short int) atol(argv[2])); srv.sin_family = AF_INET; connect(s, (struct sockaddr*) &srv, sizeof(srv)) gets(buffer); bytes = send(sock, buffer, strlen(buffer), 0); bytes = recv(s, buffer, sizeof(buffer) - 1, 0); close(s); return 0; }

Computer Net Lab/Praktikum Datenverarbeitung 2 21 Server-example in C int main(int argc, char *argv[]) { int s, c, cli_size, bytes; struct sockaddr_in srv, cli; char buffer[BUFFER_SIZE], name[BUFFER_SIZE]; s = socket(AF_INET, SOCK_STREAM, 0); srv.sin_addr.s_addr = INADDR_ANY; srv.sin_port = htons( (unsigned short int) atol(argv[1])); srv.sin_family = AF_INET; bind(s, (struct sockaddr*) &srv, sizeof(srv)); listen(s, 3); for(;;) { cli_size = sizeof(cli); c = accept(s, (struct sockaddr*) &cli, &cli_size); recv(c, name, sizeof(name) - 1, 0); name[bytes] = '\0'; printf("reveived string :%s\n",name); sprintf(buffer, "Hello %s, nice to meet you!\r\n", name); printf("send: %s",buffer); send(c, buffer, strlen(buffer), 0); close(c); }

Computer Net Lab/Praktikum Datenverarbeitung 2 22 Delphi Powerful graphical development environment. Easy to create simple application under windows. Components (i.e. text field) are placed onto a form by use of drag and drop. Support data bases, Web-Application, OLE, etc. Pascal like syntax. Supports object oriented programming. Components are easy to manipulate during development time and during runtime too. Event oriented handling of components i.e. „Click on a button“.

Computer Net Lab/Praktikum Datenverarbeitung 2 23 Sockets in Delphi Sockets under Delphi are encapsulated (winsock). Sockets are easy to configure. Open Function connects Server und Client. Intuitive and easy handling of events (i.e. OnConnect) reduces programming effort significantly.