

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of the osi and tcp/ip layers in java networking, focusing on sockets, udp, tcp, and datagrams. It covers the structure and functions of each layer, as well as practical examples of creating servers and clients using java code.
Typology: Slides
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Basic Networking in Java Calin Curescu
12 pages TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
2 of 12 TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
3 of 12 TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
4 of 12 TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
5 of 12 TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
6 of 12 TDDC32 lecture 2, 2006
import java.net.; import java.io.; public class EchoServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket = null; try { serverSocket = new ServerSocket(7); } catch (IOException e) { System.err.println("Could not listen on port: 7"); System.exit(1); } Socket clientSocket = null; try { clientSocket = serverSocket.accept(); } catch (IOException e) { System.err.println("Accept failed."); System.exit(1); } PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader( clientSocket.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { out.println(inputLine); } out.close(); in.close(); clientSocket.close(); serverSocket.close(); } }
Basic Networking in Java Calin Curescu
7 of 12 TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
8 of 12 TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
9 of 12 TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
10 of 12 TDDC32 lecture 2, 2006
import java.io.; import java.net.; public class EchoDatagramClient { public static void main(String[] args) throws IOException { if (args.length != 1) { System.out.println("Usage: java DatagramClient
Basic Networking in Java Calin Curescu
11 of 12 TDDC32 lecture 2, 2006
Basic Networking in Java Calin Curescu
12 of 12 TDDC32 lecture 2, 2006