1 Vehicle Networking Networks Instruction 1 – Echo client/server in C Jeroen Voeten ES, 2012.

Slides:



Advertisements
Similar presentations
Socket Programming Application Programming Interface.
Advertisements

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.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
Socket Programming Sample Code - simple chat client and server ee122 sp05 daron spektor.
Socket Addresses. Domains Internet domains –familiar with these Unix domains –for processes communicating on the same hosts –not sure of widespread use.
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
TCP/IP Sockets in C: Practical Guide for Programmers Michael J. Donahoo Kenneth L. Calvert.
ISP – 9 th Recitation Socket programming – Client side.
1 Socket Programming A crash-course in network programming…
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
CS3212 計算機網路概論 Winsock Tutorial
Cs423-cotter1 Example Client Program Reference Comer & Stevens, Chapter 7.
CPSC 441 TUTORIAL – JANUARY 18, 2012 TA: MARYAM ELAHI INTRODUCTION TO SOCKET PROGRAMMING WITH C.
1 Sockets Programming in Linux References: Internetworking with TCP/IP Vol III - Linux version UNIX Network Programming - W. Richard Stevens.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
CS1652 September 13th, 2012 The slides are adapted from the publisher’s material All material copyright J.F Kurose and K.W. Ross, All Rights.
Fall 2000Datacom 11 Socket Programming Review Examples: Client and Server-Diagnostics UDP versus TCP Echo.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
The Application Layer Application Services (Telnet, FTP, , WWW) Reliable Stream Transport (TCP) Connectionless Packet Delivery Service (IP) Unreliable.
Sockets API Overview Sockets with UDP Sockets with TCP Fast Sockets (Fast UDP) IP Multicasting.
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
1 Writing Network Applications using the TCP/IP Protocol Stack: Socket Programming.
Remote Shell CS230 Project #4 Assigned : Due date :
The Pocket Guide to TCP/IP Sockets: C Version Michael J. Donahoo Kenneth L. Calvert.
1 Example Servers Pt 1 Objective: To discuss key aspects of various server implementations.
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
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.
TELE202 Lecture 15 Socket programming 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »TCP/UDP (2) »Source: chapter 17 ¥This Lecture »Socket programming.
An Introductory 4.4BSD Interprocess Communication Tutorial Stuart Sechrest.
University of Calgary – CPSC 441.  A socket is an interface between the application and the network (the lower levels of the protocol stack)  The application.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Project 2: Socket Programming. Overview Sockets Working with sockets Client-Server example Project 1 Hints.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
CS3212 計算機網路概論 Winsock Tutorial. Dev C++ environment setting Download Dev-C++ from
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
Network Programming By J. H. Wang Nov. 21, Outline Introduction to network programming Socket programming –BSD Socket –WinSock –Java Socket Exercises.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: HsinYu Ha.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
In unistd.h : int gethostname(char * name, int maxlen) Purpose : Find the computer's name.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Socket programming in C. Socket programming with TCP Client must contact server server process must first be running server must have created socket (door)
The Socket Interface Client and server use the transport protocol to communicate. When it interacts with protocol, an application must specify :whether.
1 Socket Interface. 2 Client-Server Architecture The client is the one who speaks first Typical client-server situations  Client and server on the same.
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.
Sockets and Beginning Network Programming
CSCE 313 Network Socket MP8 DUE: FRI MAY 5, 2017
Part 2 Socket Programming UDP.
CS 1652 Jack Lange University of Pittsburgh
The Pocket Guide to TCP/IP Sockets: C Version
TCP/IP Sockets in C: Practical Guide for Programmers
Review: TCP Client-Server Interaction
Socket Programming in C
תקשורת ומחשוב תרגול 3-5 סוקטים ב-C.
TCP/IP Sockets in C: Practical Guide for Programmers
TCP/IP Sockets in C: Practical Guide for Programmers
Chapter 06. UDP Server/Client.
Socket Programming(1/2)
Chapter 04. TCP Server/Client.
Socket Programming Neil Tang 09/08/2008
TCP/IP Sockets in C: Practical Guide for Programmers
in unistd.h: int gethostname(char * name, int maxlen)
Presentation transcript:

1 Vehicle Networking Networks Instruction 1 – Echo client/server in C Jeroen Voeten ES, 2012

2 Assignment Building your own chat program in C++ –Bring your notebook! Download zip-file from: etworking/exercises/exercises1/EchoClientServer_V CPP2010E.zip etworking/exercises/exercises1/EchoClientServer_V CPP2010E.zip File contains example echo client and echo daemon based on TCP/IP protocol Change into UDP protocol and use it to build your own chat program 2

3 Reading material Strongly recommended utation/WinSock2.ppthttp:// utation/WinSock2.ppt et_A4.pdf (pages 1-32) et_A4.pdf Background mhttp:// m 3

4 Application (Internet Explorer Client) str2echo = ‘hello’ echo = ‘hello’ Client codeServer code sock = socket(SOCK_STREAM) bind(sock, client_address) connect(sock, server_address) send(sock, ‘hello’) receive(sock, echo) close(sock) sock = socket(SOCK_STREAM) bind(sock, server_address) accept(sock, client_address) receive(new_sock, str2echo) echo = str2echo send(sock, echo) close(sock) Streaming connections – echo Client/Server code new_sock: (IP address 2, New_Port) (IP address 1, Port 1) = client_address(IP address 2, Port 2) = server_address Application (Web Server) connect new_sock =

5 Datagram connections – echo Client/Server code sock = socket(SOCK_DGRAM) bind(sock, server_address) receive(sock, str2echo, client_address) echo = str2echo send(sock, echo, client_address) close(sock) Application (Internet Explorer Client) Application (Web Server) socket (IP address 1, Port 1) = client_address socket (IP address 2, Port 2) = server_address str2echo = ‘hello’ echo = ‘hello’ sock = socket(SOCK_DGRAM) bind(sock, client_address) send(sock, ‘hello’, server_address) receive(sock, echo, server_address) close(sock) Client codeServer code

6 Echod.c: from TCP to UDP int main(int argc, char* argv[]) { … server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = INADDR_ANY; server_address.sin_port = htons(SERVER_PORT); memset(&(server_address.sin_zero),'\0', 8); s = socket(PF_INET, SOCK_STREAM, 0); if (s == INVALID_SOCKET) { printf("Socket creation failed\n"); exit(1); } if (bind(s, (struct sockaddr *)&server_address, sizeof(server_address)) == SOCKET_ERROR) { printf("Bind failed\n"); exit(1); } listen(s, MAX_PENDING); while (true) { len = sizeof(client_address); new_s = accept(s, (struct sockaddr *)&client_address, &len); if (new_s == INVALID_SOCKET) { printf("Accepting connection failed\n"); exit(1); } n=recv(new_s, buf, sizeof(buf), 0); send(new_s,buf,n,0); closesocket(new_s); } closesocket(s); WSACleanup(); return 0; } n=recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&client_address, &len); sendto(s,buf,n,0, (struct sockaddr *)&client_address, len); s = socket(PF_INET, SOCK_DGRAM, 0);

7 Echoc: from TCP to UDP int main(int argc, char* argv[]) { … server_address.sin_family = AF_INET; server_address.sin_addr = *((struct in_addr *)hp->h_addr); server_address.sin_port = htons(SERVER_PORT); memset(&(server_address.sin_zero),'\0',8); s = socket(PF_INET, SOCK_STREAM, 0); if (s == INVALID_SOCKET){ printf("Socket creation failed"); exit(1); } if (connect(s, (struct sockaddr *)&server_address, sizeof(server_address)) == SOCKET_ERROR) { printf("Connecting to server failed"); closesocket(s); exit(1); } n = strlen(buf); send(s,buf,n,0); n=recv(s, buf, sizeof(buf), 0); buf[n] = '\0'; printf("Echo generated by server %s:\n", inet_ntoa(server_address.sin_addr)); printf(buf); closesocket(s); WSACleanup(); return 0; } s = socket(PF_INET, SOCK_DGRAM, 0); sendto(s,buf,n,0, (struct sockaddr *)&server_address, len); n=recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&server_address, &len); len = sizeof(server_address);