Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.

Slides:



Advertisements
Similar presentations
Chapter 14 Application Layer and Client-Server Model.
Advertisements

Socket Programming Application Programming Interface.
CS3516 (B10) HELP Session 2 Presented by Lei Cao.
Socket Programming: a Primer Socket to me!. Feb. 23, 2001EE122, UCB2 Why does one need sockets? application network protocol sockets network.
1 Socket Interfaces Professor Jinhua Guo CIS527 Fall 2003.
CS4514 B05 HELP Session 1 CS4514 – TCP/IP Socket Programming Presented by Feng Li
Programming with Berkeley Sockets Presented by Chris GauthierDickey Written by Daniel Stutzbach (I think!) for CIS 432/532 Useful References: ● man pages.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
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)
2: Application Layer 1 Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5th edition. Jim Kurose, Keith Ross Addison-Wesley, April.
Yu-Chi Lai Lecture 3 Network Programming CS 640: Computer Networking.
CS3212 計算機網路概論 Winsock Tutorial
Cs423-cotter1 Example Client Program Reference Comer & Stevens, Chapter 7.
Ashutosh Shukla Lecture 3 Network Programming CS 640: Computer Networking.
CPSC 441 TUTORIAL – JANUARY 18, 2012 TA: MARYAM ELAHI INTRODUCTION TO SOCKET PROGRAMMING WITH C.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
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.
9/12/2015B.R1 Socket Abstraction and Interprocess Communication B.Ramamurthy CSE421.
Sirak Kaewjamnong Computer Network Systems
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.
Ports Port - A 16-bit number that identifies the application process that receives an incoming message. Reserved ports or well-known ports (0 to 1023)
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
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.
An Introductory 4.4BSD Interprocess Communication Tutorial Stuart Sechrest.
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
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.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Chapter 2 Applications and Layered Architectures Sockets.
Client/Server Socket Programming Project
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,
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
CSCI 330 UNIX and Network Programming Unit XV: Transmission Control Protocol.
Socket Program Training 10/29/ TCP Client Socket ( ) Connect ( ) send ( ) Close ( ) send ( ) Read ( ) Accept ( ) recv ( ) Listen ( ) Bind ( ) Socket.
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.
Review: – Why layer architecture? – peer entities – Protocol and service interface – Connection-oriented/connectionless service – Reliable/unreliable service.
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
UNIX Sockets Outline UNIX sockets CS 640.
The Socket Interface A Networking Application Program Interface.
Socket programming in C. Socket programming with TCP Client must contact server server process must first be running server must have created socket (door)
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
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.
1 Vehicle Networking Networks Instruction 1 – Echo client/server in C Jeroen Voeten ES, 2012.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Socket Abstraction and Interprocess Communication
Sockets and Beginning Network Programming
CS 1652 Jack Lange University of Pittsburgh
Review: TCP Client-Server Interaction
CHAPTER 8 ELEMENTARY UDP SOCKETS
Transport layer API: Socket Programming
Introduction to Network Programming Speaker: Jae Chung
Socket Abstraction and Interprocess Communication
Berkeley API Socket Programming
Berkeley API Socket Programming
Socket Abstraction and Interprocess Communication
Chapter 06. UDP Server/Client.
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Socket Abstraction and Interprocess Communication
Berkeley API Socket Programming
Sockets.
Presentation transcript:

Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011

Platform and Compiler – Gcc: on UNIX/Linux – Dev-C++: on Windows Homepage: Version: Dev-C beta 9.2 ( ) Download and install the distributions – _setup.exe _setup.exe Configuration – [Tools]\[Compiler Options]: » Add these commands to the linker command line: -lwsock32

– Java: Java Standard Edition Development Kit (JDK) (for Linux/Windows and other environments) Homepage: nloads/index.html nloads/index.html Version: JDK 7u1 or 6u29 Download and install the JDK Configure Java environment (on Linux, for example) – setenv JAVA_HOME /usr/lib64/java – setenv MANPATH ${MANPATH}:${JAVA_HOME}/man – setenv PATH ${PATH}:${JAVA_HOME}/bin

Network Programming Exercises Sending/receiving a packet – E.g. Echo client/server (port 7) Connecting to the server: – E.g. Web server (HTTP requests) Parsing the response from the server: – E.g. HTTP responses

Datagram sockets – connectionless (UDP) – No need to establish connections before sending/receiving packets Stream socket – connection-oriented (TCP) – Establish a connection – Sending/receiving packets – Closing the connection

Sending/Receiving Packets – an Example ECHO client/server socket() close() sendto() recvfrom() socket() close() recvfrom() sendto() bind() An ECHO clientAn ECHO server

ECHO client (1/3) #include #define MAX_BUF char buf[MAX_BUF+1]; char Request[MAX_BUF+1];

ECHO client (2/3) int main(int argc, char **argv) { int nSocket, nLen, n; char ip[128]; struct sockaddr_in in; struct sockaddr_in out; if (argc > 1) strcpy(ip, argv[1]); else strcpy(ip, " "); // default: send to localhost. memset(Request, 0, MAX_BUF); printf("Please enter the message to the server (%s): \n", ip); scanf("%s", Request); printf("Sending the message to host: %s...\n", ip);

ECHO client (3/3) nSocket = socket(AF_INET, SOCK_DGRAM, 0); memset(&out, 0, sizeof(out)); out.sin_family = AF_INET; out.sin_port = htons(0x07); // port 7: Echo Service out.sin_addr.s_addr = inet_addr(ip); n = sendto(nSocket, Request, strlen(Request), 0, (struct sockaddr*)&out, sizeof(out)); printf("%d bytes sent to %08lx...\n", n, ntohl(out.sin_addr.s_addr)); n = recvfrom(nSocket, buf, MAX_BUF, 0, (struct sockaddr*)&in, &nLen); if (n == -1) perror("[ECHOc] ERROR!\n"); else printf("%d bytes received: \"%s\"\n", n, buf); close(nSocket); return 0; }

ECHO server (1/2) nSocket = socket(AF_INET, SOCK_DGRAM, 0); memset(&server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(0x07); // ECHO server server.sin_addr.s_addr = INADDR_ANY; ret = bind(nSocket, (struct sockaddr*)&server, sizeof(server)); if (ret==-1) { perror("[ECHOd] Error in bind()! "); }

ECHO server (2/2) while (1) { printf("[ECHOd] Waiting for requests...\n"); nLen = sizeof(client); n = recvfrom(nSocket, buf, MAX_BUF, 0, (struct sockaddr *)&client, &nLen); buf[n] = '\0'; printf("%d bytes received from %08lx...\n", n, ntohl(client.sin_addr.s_addr)); printf("==> [ECHOd] \"%s\"\n", buf); n = sendto(nSocket, buf, strlen(buf), 0, (struct sockaddr *)&client, nLen); printf("%d bytes sent...\n", n); printf("[ECHOd] ==> \"%s\"\n", buf); }

HTTP Request

HTTP Response