Socket programming with UDP and TCP. Socket Programming with TCP Connection oriented – Handshaking procedure Reliable byte-stream.

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

Client-Server Paradigm and Performance L. Grewe. 2 Review: Basic Client-Server Request/Reply Paradigm Typical Internet app has two pieces: client and.
Network Programming and Java Sockets
Socket Programming Socket Programming Overview Java Socket Programming
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.
2: Application Layer1 Chapter 2 (continued) Application Layer – part 2 Computer Networking: A Top Down Approach Featuring the Internet, 3 rd edition. Jim.
Lecture 11 Java Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger and Joonbok Lee.
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.
Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson.
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.
1 CMSC628: Introduction to Mobile Computing Nilanjan Banerjee Mobile Systems Programming (Acknowledgment to Deepa Shinde and Cindy Atheron University of.
2: Application Layer 1 Socket Programming TCP and UDP.
Network Applications: UDP and TCP Socket Programming Y. Richard Yang 9/17/2013.
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.
Department of Computer and IT Engineering University of Kurdistan Computer Networks II Socket programming By: Dr. Alireza Abdollahpouri.
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.
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 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
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.
2: Application Layer1 Network applications: some jargon Process: program running within a host. r within same host, two processes communicate using interprocess.
Topic: Network programming
Socket Programming Socket Programming Overview
Transport layer (last part) Application layer
DNS: Domain Name System
Socket programming with TCP
Chapter 2: outline 2.1 principles of network applications
Socket programming - Java
CSCD 330 Network Programming
Socket Programming Socket Programming Overview
Socket Programming.
CSCD 330 Network Programming
Java Socket Programming
Socket Programming 2: Application Layer.
DNS: Domain Name System
CPSC 441 UDP Socket Programming
Chapter 2: Application layer
DNS: Domain Name System
DNS: Domain Name System
Socket Programming with UDP
Presentation transcript:

Socket programming with UDP and TCP

Socket Programming with TCP Connection oriented – Handshaking procedure Reliable byte-stream

TCP-client in 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); DataOutpuStream outToServer = new DataOutputStream( clientSocket.getOutputStream()); 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(); } }

TCP-client in Java import java.io*; import java.net.*; Imports needed packages Class TCPClient { public static void main (String argv[]) throws Exception { Standard Java initiation

TCP-client in Java String sentence; String modifiedSentence; Declares two string objects BufferedReader inFromUser = new BufferedReader( new InputStreamReader(system.in)) Creates a stream that handels input from the user

TCP-client in Java Socket clientSocket = new Socket(”hostname”, 6789) ; Initiate a TCP-connection with the ”hostname” through port 6789 Client performes a DNS lookup to obtain host IP. DataOutpuStream outToServer = new DataOutputStream( clientSocket.getOutputStream()) Creates a stream that handels output to server

TCP-client in Java BufferedReader inFromServer = new BufferedReader(new InputStreamReader( clientSocket.getInputStream())); Creates a stream that handels input from server sentence = inFromUser.readLine() Puts the input from user into string object

TCP-client in Java outToServer.writeBytes(sentence + ’\n’); Transform sentence to bytes & sends to server modifiedSentence = inFromServer.readLine(); Puts input from server into modified sentence System.out.println(”FROM SERVER: ” + modifiedSentence); clientSocket.close(); } } Prints modifiedSentence and closes the connection

TCP-server in 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 connenctionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader( new InputStreamReader( connectionSocket.getInputStream())); DataOutpuStream outToClient = new DataOutputStream( connectionSocket.getOutputStream()); clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + ’\n’; outToClient.writeBytes(capitalizedSentence); }}}

TCP-server in Java ServerSocket welcomeSocket = new ServerSocket (6789); Creates a welcomeSocket that handels connection-attempts from port 6789 Socket connenctionSocket = welcomeSocket.accept(); Creates a new socket

TCP-server in Java capitalizedSentence = clientSentence.toUpperCase() + ’\n’; This command is the essence of the application.

Socket Programming with UDP Connectionless No reliable datatransfer

UDP-client in Java import java.io.*; import java.net.*; class UDPClient { public static void main(String args[ ]) throws Exception { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName(”hostname”); byte[ ] sendData = new byte[1024]; byte[ ] recieveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes (); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); clientSocket.receive(receivePacket); String modefiedSentence = new String(receivePacket.getData()); System.out.println(”FROM SERVER:” + modifiedSentence); clientSocket.close();}

UDP-client in Java DatagramSocket clientSocket = new DatagramSocket(); This line does not initiate a TCP connection InetAddress IPAddress = InetAddress.getByName(”hostname”); Uses DNS lookup to find the IP-address for ”hostname”

UDP-client in Java byte[ ] sendData = new byte[1024]; byte[ ] recieveData = new byte[1024]; Arrays that contains bytes that will be sent and recieved DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); Creates a packages that containes travel information

UDP-client in Java clientSocket.send(sendPacket); Sends the package through the client socket DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); Creates a placeholder for the package clientSocket.receive(receivePacket); Rececives the package from the server

UDP-client in Java String modefiedSentence = new String(receivePacket.getData()); Extracts the data from the package and puts it in a string package clientSocket.close(); Closes the client socket

UDP-server in Java import java.io.*; import java.net.*; class UDPClient { public static void main(String args[ ]) throws Exception { DatagramSocket serverSocket = new DatagramSocket(9876); byte[ ] receiveData = new byte[1024]; byte[ ] sendData = new byte[1024]; while(true) { DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String catitalizedSentence = sentence.toUpperCase(); sendData = capetalizedSentence.getBytes (); DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); clientSocket.send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.send(sendPacket); }}}

UDP-server in Java DatagramSocket serverSocket = new DatagramSocket(9876); Creates a socket at port 9876 that data passes through String sentence = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); Extracts the data and client information from the package