Socket Program Training 10/29/2008. 2 TCP Client Socket ( ) Connect ( ) send ( ) Close ( ) send ( ) Read ( ) Accept ( ) recv ( ) Listen ( ) Bind ( ) Socket.

Slides:



Advertisements
Similar presentations
Socket Programming in C Slides Adapted on Jörn Altmann‘s Slides.
Advertisements

Introduction to Information Security Networking. Transmission Control Protocol (aka TCP) Most widely used protocol A TCP Connection is based on 6 crucial.
Socket Programming Application Programming Interface.
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.
Quick Overview. 2 ISO/OSI Reference Model Application Application Presentation Presentation Session Session Transport Transport Network Network Data Link.
Tutorial 8 Socket Programming
CS 311 – Lecture 18 Outline IPC via Sockets – Server side socket() bind() accept() listen() – Client side connect() Lecture 181CS Operating Systems.
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)
ISP – 9 th Recitation Socket programming – Client side.
Introduction to Information Security Networking. Transmission Control Protocol (aka TCP) Most widely used protocol A ‘reliable’ (but not secure!) protocol.
Sockets CIS 370 Fall 2009, UMassD. Introduction  Sockets provide a simple programming interface which is consistent for processes on the same machine.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
Sockets and intro to IO multiplexing. Goals We are going to study sockets programming as means to introduce IO multiplexing problem. We will revisit socket.
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.
IT1352-NETWORK PROGRAMMING AND MANAGEMENT
Copyright © University of Illinois CS 241 Staff1 Network Programming.
Computer Network Sritrusta Sukaridhoto. Computer Network – Sritrusta Sukaridhoto Why Computer Network ??? Stand alone Computer …. FOR WHAT ???
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.
CS162B: IPv4 Socketing Jacob T. Chan. Socketing in the Real World  Most computer games are multiplayer in nature or have multiplayer components  DotA,
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
Computer Network Sritrusta Sukaridhoto. Why Computer Network ??? Stand alone Computer …. FOR WHAT ???
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)
Remote Shell CS230 Project #4 Assigned : Due date :
Socket Program Training 10/24/2011. Introduction Video Streaming Server –Darwin VoIP –Asterisk Socket Program –Ex: FTP Backdoor Program 2.
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.
An Introductory 4.4BSD Interprocess Communication Tutorial Stuart Sechrest.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
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.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
UNIX Sockets Outline UNIX sockets CS 640.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Carnegie Mellon Proxy & Networking : Introduction to Computer Systems – Recitation H April 11, 2011.
CS 447 Networks and Data Communication Server-Process Organization IP address and SockAddr_In Data Structure Department of Computer Science Southern Illinois.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
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.
Socket Program Training 10/27/2010. What is a Socket ? An interface between an application process and transport layer (TCP or UDP). 2.
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 PROGRAMMING Presented By : Divya Sharma.
Sockets and Beginning Network Programming
Sockets and Beginning Network Programming
CS 1652 Jack Lange University of Pittsburgh
Pertemuan 7 I/O Multiplexing
Class A Addresses The 1st bit of a class A address is 0
Introduction to Information Security
Review: TCP Client-Server Interaction
Imam Ahmad Trinugroho, ST., MMSI
Transport layer API: Socket Programming
UNIX Sockets Outline Homework #1 posted by end of day
Socket Program Training
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Presentation transcript:

Socket Program Training 10/29/2008

2 TCP Client Socket ( ) Connect ( ) send ( ) Close ( ) send ( ) Read ( ) Accept ( ) recv ( ) Listen ( ) Bind ( ) Socket ( ) recv ( ) Close ( ) Waiting for the requests from client Build a connection Data (request) Data (reply) Deal with the request TCP Server Notify the end of the file

3 FTP Server source code #include …… #define MAXDATA 1024 int main(void){ int sockfd; int recfd; int length; int filename, ndata, fdesc, fk; char buf[BUFSIZ]; char data[MAXDATA]; struct sockaddr_in myaddr; struct sockaddr_in client_addr;

4 FTP Server source code //Get a socket into TCP/IP if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){ perror("socket error"); //write error messages to standard error return 0;} // AF_INET  IPv4, AF_INET6  IPv6 //SOCK_STREAM  TCP, SOCK_DGRAM  UDP //Set up address memset((char*)&myaddr,0,sizeof(myaddr)); myaddr.sin_family=AF_INET; myaddr.sin_addr.s_addr=htonl(INADDR_ANY); myaddr.sin_port=htons(1234);

5 FTP Server source code if(bind(sockfd,(struct sockaddr*)&myaddr,sizeof(myaddr))<0){ perror("bind failed"); return 0;} if(listen(sockfd,1)<0){ perror("listen error"); return 0;} //Loop continuously, waiting for connection requests and performing the service length=sizeof(client_addr); printf("Server start !\n");

6 FTP Server source code while(1){ if((recfd=accept(sockfd,(struct sockaddr*)&client_addr,&length))<0){ perror("accept error"); return 0;} if((fk=fork())<0){ perror("fork error"); exit(1);} if(fk==0){ if((filename=read(recfd,buf,BUFSIZ))<0){ perror("server read error"); return 0;}

7 FTP Server source code printf("Create socket #%d from %s : %d\n",recfd,inet_ntoa(client_addr.sin_addr),htons(client_addr.sin_p ort)); printf("receive: %s\n",&buf); //Reserve two parts for you (fdesc=open(buf,O_RDONLY) perror (ndata=read(fdesc,data,MAXDATA)

8 FTP Server source code //return to client if((write(recfd,buf,ndata))<0){ perror("server write error"); return 0;} memset(buf,0,sizeof(buf)); close(recfd);} close(sockfd); return 0;}

9 FTP Client source code int main (int argc, char *argv[]) //ex: file option1 option2 option3 //argc = 4, argv[0]="file“,argv[1]="option1“, argv[2]="option2“,argv[3]="option3" { …… int ndata, fdesc, k, fk, index; int nbytes, count; …… //Check for proper usage if(argc < 4){ printf("use : ftpc IP file_count file1 file2...\n"); return 0;}

10 FTP Client source code count=atoi(argv[2]); printf("%d files request!\n",count); index=3; for(k=0;k<count;k++){ if((fk=fork())<0){ perror("fork error!");} if(fk==0){ if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){ printf("socket error\n"); return 0;}

11 FTP Client source code …… //Reserve two parts for you write(sockfd,argv[ ],strlen(argv[ ]) perror fdesc=open(argv[ ],O_WRONLY|O_CREAT|O_APPEND); Index; perror

12 FTP Client source code for(;;){ if((nbytes=read(sockfd,&buf,BUFSIZ))<0){ perror("first read"); exit(1);} if(nbytes==0){ printf("file %s transmit complete ! \n",argv[ ]); close(fdesc); close(sockfd); exit(1); break;} else{ if(write(fdesc,&buf,nbytes)<0){ perror("write error!"); exit(1); ……

13 Compile gcc -o filename filename.c –# gcc -o server server.c –# gcc -o client client.c Execute the filename –#./filename –#./filename server_IP number_of_file file1 file2 file3

Tcpdump and Tcpstat

15 Tcpdump and Tcpstat Listen the interfaces (network cards) of the router and write into a dump file. –Tcpdump options –-i, -w Also listen the interfaces of the server and client.

16 Tcpdump and Tcpstat Gather statistics from the dump files. –Tcpstat options –-r, -f ‘ ‘, -o “ “ Filter out the three different files. –Tcpdump primitives –port, src net,

17 Tcpdump and Tcpstat Output formatting –%a: the average packet size –%b: the number of bits per second –%I: the number of IPv4 packets –%n the number of packets –%p: the number of packets per second