Lab2: Socket Programming Lecturer: Mauro Conti T.A.: Eyüp S. Canlar.

Slides:



Advertisements
Similar presentations
Lab4: Theory + GUI Lecturer: Mauro Conti T.A.: Eyüp S. Canlar.
Advertisements

1 Streams and Input/Output Files Part 2. 2 Files and Exceptions When creating files and performing I/O operations on them, the systems generates errors.
Jan Java I/O Yangjun Chen Dept. Business Computing University of Winnipeg.
Lecture 15: I/O and Parsing
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Referring to Java API Specifications
Lab1: File I/O and Streams Lecturer: Mauro Conti T.A.: Eyüp S. Canlar.
COEN 445 Communication Networks and Protocols Lab 4
Network Read/Write. Review of Streams and Files java.io package InputStream and OutputStream classes for binary bytes Reader and Writer classes for characters.
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.
Programming Applets How do Applets work ? This is an HTML page This is the applet’s code It has a link to an applet.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
Java Networking -- Socket Server socket class: ServerSocket wait for requests from clients. after a request is received, a client socket is generated.
Client/Server example. Server import java.io.*; import java.net.*; import java.util.*; public class PrimeServer { private ServerSocket sSoc; public static.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Java sockets. From waiting.
System Programming Practical session 11 Multiple clients server Non-Blocking I/O.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
Performance measurements for inter-process communication.
Web Security Programming I Building Security in from the Start Except where otherwise noted all portions of this work are Copyright (c) 2007 Google and.
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.
Session 05 Java Strings and Files. Exercise Complete the “quick-and-dirty” class CharacterCounter containing only a main() method that displays the number.
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
Lab 6: Introduction to Sockets (Web Programming – Part 1) Reference: Head First Java (2 nd Edition) by Kathy Sierra & Bert Bates.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Network Programming and Sockets CPSC 363 Computer Networks Ellen Walker Hiram College (Includes figures from Computer Networking by Kurose & Ross, © Addison.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
Servlet Communication Other Servlets, HTML pages, objects shared among servlets on same server Servlets on another server with HTTP request of the other.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
© Amir Kirsh Java Networking Written by Amir Kirsh.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
Lab 2C Primer I/O in Java Sockets Threads More Java Stuffs.
File IO Basics By Dan Fleck Coming up: Data Streams.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
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,
Lab 2 Primer Assignment 3 Structure File I/O More parsing and HTTP Formatting.
CSC 480 Software Engineering Socket. What is Socket? A socket is one end-point of a two-way communication link between two programs running on the network.
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.
Servers and Sockets Carol Wolf Computer Science. Java network programming classes  SocketImpl – abstract class and superclass of the rest  Four fields:
CS101 Lab “File input/Output”. File input, output File : binary file, text file READ/WRITE class of “text file” - File Reading class : FileReader, BufferedReader.
Lecture 5 I/O and Parsing
CIS Intro to JAVA Lecture Notes Set 6 2-June-05.
Java Server Programming Web Interface for Java Programs.
1 CSCD 330 Network Programming Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 9 Client-Server Programming.
Lab assignments in Computer Networks at Faculty of Electronic Engineering - Nis.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Distributed Systems CS Project 1: File Storage and Access Kit (FileStack) Recitation 1, Aug 29, 2013 Dania Abed Rabbou and Mohammad Hammoud.
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
Web Server Assignment1 Reference ( Main class (for example : MyServer.java) –Initialization.
Liang, Oreilly, Herbert Schildt, Joseph O’Neil, Simon Roberts, IBM Corp Advanced Java Programming CSE 7345/5345/ NTU 531 Multithreaded/Sockets/Server Welcome.
SOCKET PROGRAMMING.
Threads in Java Two ways to start a thread
Java Exceptions and I/O
Client-server Programming
Networking with Java 2.
EE 422C Socket Programming
Lecture 11 Socket Programming.
Chapter 2: outline 2.1 principles of network applications
Socket programming - Java
Reading and Writing Text Files
HTTP and Sockets Lecture 6
Introduction to Client/Server Design
Uniform Resource Locators
Socket Programming 2: Application Layer.
CPSC 441 UDP Socket Programming
EEC 484/584 Computer Networks
Presentation transcript:

Lab2: Socket Programming Lecturer: Mauro Conti T.A.: Eyüp S. Canlar

Exercise 1 Write a client and a multi-threaded server program  Clients send a message to the server Usage: java Lab2Client  Server prints the message out Usage: java Lab2Server

Exercise 1: client and server //Client code Socket socket = new Socket(“localhost”, 12345); //Send message …. //Server code ServerSocket servSocket = new ServerSocket(12345); while(true){ Socket cliSocket = servSocket.accept(); //Create a thread to handle //client print request }

Exercise 2 Write a program HttpGet.java  Usage: java HttpGet  Requirements: int start(String[] argv)  Initialize Socket, BufferedReader, and BufferedWriter void sendGetRequest(String filename, BufferedWriter out) throws IOException  Send GET request: “GET /path/index.html HTML/1.0\r\n\r\n” void receiveGetResponse(BufferedReader in) throws IOException  Reads the response and prints it line by line on standard output

Exercise 2: start(String[] argv) public void start(String[] argv){ try{ Socket socket = new Socket(argv[0]); BufferedReader in = new BufferedReader(new InputStreamReader( socket.getInputStream())); BufferedWriter out = new BufferedWriter(new OutputStreamWriter( socket.getOutputStream()); …. } catch(Exception e){….} }

Exercise 2: send and receive Sending GET request  out.write(getRequest); out.flush(); Receiving reply from web server  while (line = in.readln() != null){….}

Exercise 3 Modify the program of Exercise 1 to store the received file. To achieve this:  Write a method to parse the path to distil the filename  Send GET request and receive reply  Skip the header of the reply and store the remainder in the local file

Exercise 3: parsing the path StringTokenizer strtok = new StringTokenizer(path, “/”); //skip all the tokens until the last one …. filename = strtok.nextToken();

Exercise 3: parsing reply while(/*some condition*/){ line = in.readLine(); if(line=“” && !firstEmptyLine){ //We reached the end of the header } if(firstEmptyLine){ //Start reading payload }