Network and Sockets Today: Get started doing network programming

Slides:



Advertisements
Similar presentations
ZSocket address structure in : struct sockaddr{ u_shortsa_family;/* address family: AF_xxx value */ charsa_data[14];/* up to 14 bytes of protocol- */ /*
Advertisements

CHAIMS CPAM in TCP/IP Cho Chan and Kun Jiang Nov. 30, 1998 CS 446.
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.
Socket Programming.
Design, implementation and evaluation issues of local area network devices 期末 DEMO Elementary SCTP Socket Functions & Client/Server Example 陳旻槿.
TDC561 Network Programming Camelia Zlatea, PhD Week 2 – part II: Socket Application Programming Interface.
UDP: User Datagram Protocol. UDP: User Datagram Protocol [RFC 768] r “bare bones”, “best effort” transport protocol r connectionless: m no handshaking.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
1) The server should be concurrent. This implies that it should loop infinitely, listening for clients requests. It should NOT terminate after accepting.
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)
Network Programming Using Internet Sockets Wu Xuanxuan Lai Xinyu 吴璇璇 赖新宇
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.
ECE453 – Introduction to Computer Networks Lecture 15 – Transport Layer (II)
ECE 4110 – Internetwork Programming Client-Server Model.
Computer Networks Lecture 1 Adrian Sergiu DARABANT.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Elementary TCP Sockets
Zhu Reference: Daniel Spangenberger Computer Networks, Fall 2007 PPT-4 Socket Programming.
Copyright © University of Illinois CS 241 Staff1 Network Programming.
Chapter 8 Elementary UDP Socket. Contents u recvfrom and sendto Function u UDP Echo Server( main, de_echo Function) u UDP Echo Client( main, de_cli Function)
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.
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 :
Building Highly Distributed Systems Within 5 Minutes 1 iCSC2014, Jonas Kunze, University of Mainz – NA62 Network Programming Lecture 2 Building Highly.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
Distributed Computing A Programmer’s Perspective.
CSE/EE 461 Getting Started with Networking. 2 Basic Concepts A PROCESS is an executing program somewhere. –Eg, “./a.out” A MESSAGE contains information.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Introduction A Simple Daytime Client A Simple Daytime Server
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.
Review: – Why layer architecture? – peer entities – Protocol and service interface – Connection-oriented/connectionless service – Reliable/unreliable service.
OS view of networking – Sockets API (an exercise in planning for the future) David E. Culler CS162 – Operating Systems and Systems Programming Lecture.
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
Carnegie Mellon Proxy & Networking : Introduction to Computer Systems – Recitation H April 11, 2011.
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
Socket Programming Jignesh Patel Palanivel Rathinam connecting processes.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
Sockets API Developing Applications using the Sockets API.
Netprog: TCP Sockets1 TCP Sockets Programming Creating a passive mode (server) socket.Creating a passive mode (server) socket. Establishing an application-level.
SOCKET PROGRAMMING Presented By : Divya Sharma.
Cs288 Intensive Programming in Linux
Cs288 Intensive Programming in Linux
Internet Socket Programing
CS 1652 Jack Lange University of Pittsburgh
Socket Programming in C
Socket Programming in C
Transport layer API: Socket Programming
UNIX Domain sockets The Linux Programming Interface (ch 57)
Network Programming CSC- 341
CSE454 Internet Technology. Asst. Prof. Dr
TCP Sockets Programming
Advanced Network Programming spring 2007
TCP/IP Socket Programming in C
SISTEMET E SHPERNDARE (DISTRIBUTED SYSTEMS)‏ TCP Sockets
Chapter 2 Application Layer
Elementary UDP Sockets connectionless, unreliable, datagram
Socket Programming(1/2)
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Today’s topic: Basic TCP API
Presentation transcript:

Network and Sockets Today: Get started doing network programming Reliable socket programming Aka TCP programming

setup A number of PCs running XP and cygwin (tested) Vista/W7 and cygwin (not ! tested) Linux/ubuntu/... (tested) Mac OSX (not tested but …) Or linux livecd on PC (tested) Why ? Because !

How ? Short !!! lecture Back and programming !!! :-) You can only programming by programming !

A TCP socket is A reliable connection You get data correct transferred Or not valid data through No size limit of data – you can “stream” a movie Although size of buffers matters A unreliable link is a UDP socket Unreliable – no check on data and on if they were received ok 64 B limit on each transaction (read/write)

TCP – the reliable one

UDP socket – the unreliable

Compared to … files file_handle = fopen (“jens”,..) write(file_handle,” ost\n”); read(file_handle,...) Etc /* so close to file operations ! */

Sockit ;-) fgets(buffer,255,stdin); n = write(sockfd,buffer,strlen(buffer)); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = read(sockfd,buffer,255);

Server versus client SERVER The server shall be ready to accept a call from a client IS not aware of clients IP address prior to call Server and client must agree on ping pong protocol Normally at design stage ! Server may be able to handle more than one call at a time (call desk :-)

Server versus client CLIENT Try to connect to a server Must know server IP and port(1..65535) Your server should use ports above 10000 Some ports: (from /etc/services) finger 79/tcp www 80/tcp http www 80/udp link 87/tcp ttylink kerberos 88/tcp kerberos5 krb5 kerberos 88/udp kerberos5 krb5

int sockfd; sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); bzero((char *) &serv_addr, sizeof(serv_addr)); portno = atoi(argv[1]); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) error("ERROR on accept");

if (newsockfd < 0) error("ERROR on accept"); bzero(buffer,256); n = read(newsockfd,buffer,255); if (n < 0) error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); n = write(newsockfd,"I got your message",18);