Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson.

Slides:



Advertisements
Similar presentations
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r Sockets are explicitly created, used, released by applications.
Advertisements

Network Programming and Java Sockets
Application Layer 2-1 Chapter 2 Application Layer Computer Networking: A Top Down Approach 6 th edition Jim Kurose, Keith Ross Application Layer – Lecture.
2: Application Layer 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
9/23/2003-9/25/2003 Sockets & DNS September 23-25, 2003.
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
2: Application Layer1 Data Communication and Networks Lecture 12 Java Sockets November 30, 2006.
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
1 Review of Previous Lecture r Electronic Mail r DNS r P2P file sharing.
Internet and Intranet Protocols and Applications Lecture 4: Application Layer 3: Socket Programming February 8, 2005 Arthur Goldberg Computer Science Department.
Networking Overview February 2, /2/2004 Assignments Due – Homework 0 Due – Reading and Warmup questions Work on Homework 1.
2: Application Layer1 Chapter 2 (continued) Application Layer – part 2 Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim.
Socket programming with UDP and TCP. Socket Programming with TCP Connection oriented – Handshaking procedure Reliable byte-stream.
TCP Socket Programming. r An abstract interface provided to the application programmer  File descriptor, allows apps to read/write to the network r Allows.
TCP Socket Programming CPSC 441 Department of Computer Science University of Calgary.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
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,
1 Network Layers Application Transport Network Data-Link Physical bits.
Protocols Rules for communicating between two entities (e.g., a client and a server) “A protocol definition specifies how distributed system elements interact.
2: Application Layer 1 Socket Programming Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim Kurose, Keith Ross Addison-Wesley,
JAVA Socket Programming Joonbok Lee KAIST.
2: Application Layer 1 Socket Programming TCP and UDP.
JAVA Socket Programming Source: by Joonbok Lee, KAIST, 2003.
ECE5650: Network Programming
1 1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
2: Application Layer1 Chapter 2 Application Layer Computer Networking: A Top Down Approach Featuring the Internet, 2 nd edition. Jim Kurose, Keith Ross.
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,
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
CS 3830 Day 11 Introduction : Application Layer 2 Server-client vs. P2P: example Client upload rate = u, F/u = 1 hour, u s = 10u, d min ≥ u s.
18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion.
1 CS: 4244 Internet Programming Sockets Programming Dr. Eli Tilevich January 29, 2007.
Chapter 2 Application Layer Computer Networking: A Top Down Approach, 5 th edition. Jim Kurose, Keith Ross Addison-Wesley, April A note on the use.
Winter 2002Suprakash Datta1 Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
-1- Georgia State UniversitySensorweb Research Laboratory CSC4220/6220 Computer Networks Dr. WenZhan Song Associate Professor, Computer Science.
1 CSCD 330 Network Programming Winter 2015 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Socket Programming Lee, Sooyong
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
Socket Programming Tutorial. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
Java Socket programming. Socket programming with TCP.
NETWORK 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,
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
1 CSCD 330 Network Programming Spring 2014 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 7 Application.
Chapter 2 Application Layer Application 2-1. Chapter 2: Application layer 2.1 Principles of network applications 2.2 Web and HTTP 2.3 FTP 2.4 Electronic.
1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm r two types of.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
CPSC Application Layer 1 Trying out HTTP (client side) for yourself 1. Telnet to your favorite Web server: Opens TCP connection to port 80 (default.
1 CSCD 330 Network Programming Winter 2016 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 6 Application.
Network Applications: Network App Programming: TCP FTP Y. Richard Yang 2/8/2016.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
1 All rights reserved to Chun-Chuan Yang Upon completion you will be able to: The OSI Model and the TCP/IP Protocol Suite Understand the architecture of.
Topic: Network programming
Socket Programming Socket Programming Overview
Client-server Programming
DNS: Domain Name System
Socket programming with TCP
CSCD 330 Network Programming
DMET 602: Networks and Media Lab
Chapter 2: outline 2.1 principles of network applications
Socket programming - Java
Socket Programming Socket Programming Overview
Socket Programming.
CSCD 330 Network Programming
Java Socket Programming
Socket Programming 2: Application Layer.
DNS: Domain Name System
DNS: Domain Name System
DNS: Domain Name System
Presentation transcript:

Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson

CIS 235: Networks Fall, 2007 Western State College Sockets Most low level network programming is done using an abstraction called “sockets”. There are lots of socket libraries that we can use to build applications that exploit network connections. Sockets differ from files in that you have to go through a connection process and the connection may go away. Sockets differ from streams in that there can be a loss of connection. We can do either UDP or TCP over sockets – this will depend on the application

CIS 235: Networks Fall, 2007 Western State College Networks and the OS You won’t get to program at the hardware level when you write network code – the operating system (Windows / Linux) wants to control the actual network devices. The OS will handle the TCP/UDP/IP protocol for you – you’ll never see this level of the system except for a few “tuning parameters” that are available to you.

CIS 235: Networks Fall, 2007 Western State College TCP Sockets TCP is a connection oriented service – a program will have to set up / tear down the connection. A socket is similar to any other data source – data arrives whenever it feels like it (as with terminal input) and the program needs to respond to it.

CIS 235: Networks Fall, 2007 Western State College TCP Sockets * Client creates a socket to build a connection * Using the socket, the client establishes a connection with the server * Ultimately we get a connection socket that provides reliable byte stream service between client and server * Stream: a flow of characters between two program components. How have we seen streams implemented?

CIS 235: Networks Fall, 2007 Western State College Port Numbers Messages arriving at your computer get there because they are directed to your IP address But how do we know which application a message is associated with? Port numbers are used to identify a specific software object on a computer that is associated with a particular piece of traffic.

CIS 235: Networks Fall, 2007 Western State College Static Port Numbers A server needs to be at a known port number. Many ports are pre-allocated to specific services (25 = SMTP, 80 = www) If a packet arrives at a machine unsolicited it has to be at a known port

CIS 235: Networks Fall, 2007 Western State College Dynamic Port Numbers When you initiate a connection with another machine, you need to allocate a port number for the reply message. Your OS keeps a pool of unused port numbers to use as “reply-to” addresses for connections established to other machines. You don’t care which port is used – only that no other application can use that port while you are.

CIS 235: Networks Fall, 2007 Western State College The Mail Room The operating system is responsible for “sorting the mail”. That is, incoming messages are sorted by port number to associate them with the proper application. It is essential for the OS to know about any static port associations and to manage dynamic ports without running out of port numbers. The number of ports (65K?) limits the number of networked applications you can run at once.

CIS 235: Networks Fall, 2007 Western State College Example: Socket Programming The following code demonstrates a TCP client / Server. These programs use port 6789 to find the server The client sends a string to the server and then receives a reply consisting of the same string in all caps Please get on a computer and start netbeans. I’d like 3 servers and 6 clients – copy the appropriate project out of my shared folder into your S folder. We’ll talk code while it gets going!

CIS 235: Networks Fall, 2007 Western State College TCP Client/Server Interaction wait for incoming connection request connectionSocket = welcomeSocket.accept() create socket, port= x, for incoming request: welcomeSocket = ServerSocket() create socket, connect to hostid, port= x clientSocket = Socket() close connectionSocket read reply from clientSocket close clientSocket Server (running on hostid ) Client send request using clientSocket read request from connectionSocket write reply to connectionSocket TCP connection setup

CIS 235: Networks Fall, 2007 Western State College TCPClient.java import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); Create input stream Create client socket, connect to server Create output stream attached to socket

CIS 235: Networks Fall, 2007 Western State College TCPClient.java BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println ("FROM SERVER: " + modifiedSentence ); clientSocket.close(); } Create input stream attached to socket Send line to server Read line from server

CIS 235: Networks Fall, 2007 Western State College TCPServer.java import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket

CIS 235: Networks Fall, 2007 Western State College TCPServer.java DataOutputStream outToClient = new DataOutputStream (connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); } Read in line from socket Create output stream, attached to socket Write out line to socket End of while loop, loop back and wait for another client connection

CIS 235: Networks Fall, 2007 Western State College TCP Sockets TCP is a connection oriented service – a program will have to set up / tear down the connection. A socket is similar to any other data source – data arrives whenever it feels like it (as with terminal input) and the program needs to respond to it.

CIS 235: Networks Fall, 2007 Western State College TCP Sockets * Client creates a socket to establish a connection with the server * Using the socket, the client establishes a connection with the server * Ultimately we get a connection socket that provides reliable byte stream service between client and server * Stream: a flow of characters between two program components. How have we seen streams implemented?

CIS 235: Networks Fall, 2007 Western State College A TCP Client import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream( clientSocket.getOutputStream());

CIS 235: Networks Fall, 2007 Western State College A TCP Client BufferedReader inFromServer = new BufferedReader( new InputStreamReader( clientSocket.getInputStream())); sentence = inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence = inFromServer.readLine(); System.out.println( "FROM SERVER: " + modifiedSentence); clientSocket.close(); } }

CIS 235: Networks Fall, 2007 Western State College The Hostname We’ll avoid DNS issues and use a raw IP address. Use the ipconfig utility if you are a server so you can tell others what your IP address is.

CIS 235: Networks Fall, 2007 Western State College A TCP Server import java.io.*; import java.net.*; class TCPServer { public static void main(String argv[]) throws Exception {String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept();

CIS 235: Networks Fall, 2007 Western State College A TCP Server BufferedReader inFromClient = new BufferedReader( new InputStreamReader( connectionSocket.getInputStream())); DataOutputStream outToClient = new DataOutputStream( connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + '\n'; outToClient.writeBytes(capitalizedSentence); }}}