Network Programming. Powered by Pentalog. by Vlad Costel Ungureanu for Learn Stuff

Similar documents
Networking Basics. network communication.

Java Networking (sockets)

Programare avansată Programare în rețea

Java Technologies. Lecture VII. Valdas Rapševičius. Vilnius University Faculty of Mathematics and Informatics

Distributed Programming - Sockets

CPSC 441 Tutorial TCP Server. Department of Computer Science University of Calgary

Lecture 3: Socket Programming

protocols September 15,

Previous lecture: threads G51PRG: Introduction to Programming Second semester Lecture 12 URL

Assignment 1. Due date February 6, 2007 at 11pm. It must be submitted using submit command.

Network. Dr. Jens Bennedsen, Aarhus University, School of Engineering Aarhus, Denmark

Verteilte Systeme UE Important Code

Basic Java Network Programming. CS211 July 30 th, 2001

URL Kullanımı Get URL

Network Programming Benoît Garbinato

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

Chapter 12. Network Programming

Software Practice 1 - Socket

Advanced Java Programming. Networking

Input from Files. Buffered Reader

Java Socket Workshop. July Purpose of this workshop:

Principles, Models and Applications for Distributed Systems M

JAVA 프로그래밍 II. Lab #7 (Networking) TCP Java Socket. TCP vs UDP 2017 학년도 1 학기 년봄학기 5/24/2017 박경신. Client. Server

Unit 1 Java Networking

Java 6. Network programming

CS September 2017

Lab 1 : Java Sockets

Socket 101 Excerpt from Network Programming

Lecture 11.1 I/O Streams

Networking in Java. Java Fundamentals. Dmitri Gabbasov Tartu 2016

Java Programming Language Advance Feature

CS193j, Stanford Handout #26. Files and Streams

I/O Streams. Object-oriented programming

Java for Interfaces and Networks

Java.net Package and Classes(Url, UrlConnection, HttpUrlConnection)

CS 351 Design of Large Programs Sockets Example

public static void main(string[] args) throws IOException { sock = new Socket(args[0], Integer.parseInt(args[1]));

Multimedia Programming

Internet Technology 2/7/2013

CPSC 441 Assignment-3 Discussion. Department of Computer Science University of Calgary

Distributed Systems. 3. Access to the Transport Layer. Werner Nutt

BrickNet (cont d) Other Academic Projects

Transport layer protocols. Lecture 15: Operating Systems and Networks Behzad Bordbar

Pieter van den Hombergh Richard van den Ham. March 17, 2018

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

Java for Interfaces and Networks (DT3029)

Java for Interfaces and Networks (DT3010, HT11)

Java A.1 TCP/IP TCP. TCP_RO.java import java.net.*; import java.io.*;

CS 251 Intermediate Programming Java I/O Streams

Principles of Software Construction. Introduction to networks and distributed systems School of Computer Science

Network Programming 1

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Introduction to Network Programming using Java

File IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20

Interprocess Communication

Introduction to Sockets 9/25/14

TCP connections. Fundamentals of Internet Connections Objectives. Connect to an Echo port. java.net.socket

CPSC 441 Assignment-3 Discussion. Department of Computer Science University of Calgary

Darshan Institute of Engineering & Technology for Diploma Studies

Objec&ves. Review. Standard Error Streams

Java networking using sockets

Java for Interfaces and Networks (DT3029)

Project 0. Danyang Zhuo CSE sp Sec;on #2

CS 2113 Software Engineering

Object-Oriented Software Engineering (Re-exam for Object-Oriented Analysis, Design and Programming)

Multi-threaded Web Server (Assignment 1) Georgios Georgiadis

Input, Output and Exceptions. COMS W1007 Introduction to Computer Science. Christopher Conway 24 June 2003

IT101. File Input and Output

PIC 20A Streams and I/O

Networking Code CSCI 201 Principles of Software Development

CSCD 330 Network Programming Spring 2018

Today. cisc3120-fall2012-parsons-lectiv.2 2

Java Development: Do s and Don ts

CSCD 330 Network Programming Winter 2019

31 Network Programming

Networking and Security

CSCD 330 Network Programming Spring 2018

CS 5010: PDP. Lecture 11: Networks CS 5010 Fall 2017 Seattle. Adrienne Slaughter, Ph.D.

Example: Copying the contents of a file

Introduction to Sockets

Socket Programming(TCP & UDP) Sanjay Chakraborty

Reading from URL. Intent - open URL get an input stream on the connection, and read from the input stream.

Reliability is an issue. You cannot afford to have any of the data lost or re-ordered.

"protocol stack! chat. Java

CPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary

Chapter 2 Applications and

Byte and Character Streams. Reading and Writing Console input and output

JAVA SOCKET PROGRAMMING

CSS 533 Program 2: Distributed Java Space Servers Professor: Munehiro Fukuda Due date: see the syllabus

Basic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2

Distributed Programming

Networking SYSTEM SOFTWARE 1

Lecture 4: Exceptions. I/O

Sockets and RMI. CS151 Chris Pollett Dec. 5, 2005.

Info 408 Distributed Applications programming 2 nd semester of 2017/2018 Credits: 5 Lecturer: Dr. Antoun Yaacoub

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017

1.00 Lecture 30. Sending information to a Java program

Chapter 9: UDP sockets & address conversion function

Introduction Unit 4: Input, output and exceptions

Project Report On. Multiple Client and Server ChatApplication using Multicast in Java WindowBuilder

Transcription:

Network Programming by Vlad Costel Ungureanu for Learn Stuff

Java Network Protocols 2

Java Network Protocols 3

Addresses Innet4Address (32-bit) 85.122.23.145 - numeric pentalog.com symbolic Innet6Address (128-bit) 2002:0:0:0:0:0:557a:1791 Types of addresses unicast multicast localhost (127.0.0.1) 4

Ports A port is a 16 bit number that uniquely identifies a process that provides network services Port number values: Possible values: 0 65535 Reserved values: 0 1023(usually for OS services or well known applications) 5

Server Client Model Server offers network services responds at a specific port needs to be able to handle concurrent requests Client initiates the conversation with the server needs to know the network address and the port of the server requests a specific service from the server 6

Sockets 7

Sockets Socket = software abstraction describing the edges of a connection TCP: Socket, ServerSocket UDP: DatagramSocket InetSocketAddress IP address, port host name, port 8

TCP Servers public class SimpleServer { public SimpleServer() throws IOException { ServerSocket serversocket = null ; try { serversocket = new ServerSocket(8100); while ( true ) { Socket socket = serversocket.accept(); // execute client request new ClientThread(socket).start(); } } catch ( IOException e) { System.err. println ( You should log this error! ); } finally { serversocket.close(); } } public static void main ( String [] args ) throws IOException { SimpleServer server = new SimpleServer (); }} 9

TCP Response class ClientThread extends Thread { private Socket socket = null ; public ClientThread ( Socket socket ) { this.socket = socket ; } public void run () { try { BufferedReader in = new BufferedReader ( new InputStreamReader (socket.getinputstream())); String request= in.readline (); PrintWriter out = new PrintWriter (socket.getoutputstream()); String response = " Hello " + request+ "!"; out.println (response ); out.flush (); } catch (IOException e) { System.err.println("Eroare IO \n" + e); } finally { try { socket.close(); } catch ( IOException e) { System.err. println (e); } }}} 10

TCP Client public class SimpleClient { public static void main (String[] args) throws IOException { Socket socket = null ; PrintWriter out = null ; BufferedReader in = null ; try { socket = new Socket ("127.0.0.1", 8080); out = new PrintWriter (socket.getoutputstream(), true); out.println ( Vlad ); out.close(); in = new BufferedReader ( new }} InputStreamReader(socket.getInputStream ())); raspuns = in.readline (); in.close(); } catch ( UnknownHostException e) { System.err.println (e); } finally { socket.close(); } 11

UPD Server DatagramSocket socket = new DatagramSocket(8200); byte buf[] = new byte[256]; DatgramPacket request = new DatagramPacket(buf, buf.length ); socket.receive(request ); InetAddress clientaddress= request.getaddress(); int clientport= request.getport(); String message= " Hello " + new String(clientPort.getData()); buf = message.getbytes(); DatagramPacket response= new DatagramPacket(buf, buf.length, clientaddress, clientport); socket.send(response); 12

UPD Client InetAddress serveraddress= InetAddress.getByName("127.0.0.1"); int serverport = 8200; DatagramSocket socket = new DatagramSocket(); byte buf[] = Vlad".getBytes (); DatagramPacket request = new DatagramPacket(buf, buf.length, serveraddress, serverport); socket.send(request); buf[] = new byte [256]; DatagramPacket response= new DatagramPacket(buf, buf.length ); socket.receive(response); System.out.println(new String(response.getData())); 13

Reading URL content try { URL url = new URL ( some_url_address ); InputStream in = url.openstream(); br = new BufferedReader (new InputStreamReader (in)); String linie ; while (( linie = br. readline ())!= null ) { System.out.println (linie); } } catch ( MalformedURLException e) { System. err. println ( You should log this error! ); } finally { if (br!= null) { br. close (); } } 14

Connecting to an URL try { URL url = new URL("http://localhost:8080/App/HelloWorld); URLConnection connection = url.openconnection(); connection.setdooutput(true); OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream()); String param = URLEncoder.encode("Duke & World", "UTF-8"); out.write("string=" + param); out.close(); BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream())); String response; while ((response = in.readline())!= null) { System.out.println(response); } in.close(); } catch (Exception e) { System. err. println ( You should log this error! ); } } 15

JNDI 16

RMI 17

Assignments Using Swing, Threads and Networking create a chat application that allows for users to send users to one another For simplicity use a Thread on the client that checks for new messages on the server Create a simple application that reads the content of a site and extracts all the domain related links. Extend the application to recursively follow links and creates a site map. 18

THANK YOU! Vlad Costel Ungureanu ungureanu_vlad_costel@yahoo.com This is a free course from LearnStuff.ro not for commercial use 19