Presentation is loading. Please wait.

Presentation is loading. Please wait.

Networking COMP 112 2017.

Similar presentations


Presentation on theme: "Networking COMP 112 2017."— Presentation transcript:

1 Networking COMP

2 Basic Networking Network comunication Admin
Vast basket of things that different users want Design metaphore to give: Different interfacces for different users And an understandable code structure Admin

3 Networking Computers are (mostly) networked i.e. connected to bits of hardware some being computers: desktops, laptops embedded controllers servers phones sensors Users expect to be able communicate with the world Computers increasingly require networking to operate How does networking function? How can we write programs that use the network?

4 What’s required to communicate?
Users do not need to understand what goes on inside this bubble Java application programmers only need a shallow understanding of the bubble

5 Shopping basket of networking wants
Transmit a character over a specific wire or fibre Send data to machine where no direct connection exists Split a message into “packets” and rebuild Deal with multiple packets from multiple computers on the same wire at the same time Correct transmission errors Real time data transmission Manage a “conversation” with a distant server. Software reconfiguration around hardware failure Design metaphor to structure networking software

6 Levels of communication
Different users appear to communicate at different levels Transmit a character over a specific wire or fibre Send Simultaneous multiple packets from multiple computers Send Movie Manage a “conversation” with a distant server.

7 Protocol Stack – design metaphor
Layers of programs that build on each other. Each layer calls methods provided by the layer below Applications only appear to have direct communication Actual communication occurs at the lowest layer It only appears that a mail program sends an . Application Layer Application Transport Layer Internet Layer Network Access Layer Network

8 TCP/IP Stack Network Access Layer (eg, Ethernet protocol)
Part of the operating system Encoding a packet into signals to go over a wire/fibre/wireless to the computer at the other end of the wire, and decoding it. Dealing with collisions – two computers sending at the same time

9 TCP/IP Stack Internet Layer (eg, IP protocol) Network Access Layer
Part of operating system Encoding information into a packet with address information Dealing with addresses and routing a packet to the target computer at the other side of the network. Network Access Layer

10 TCP/IP Stack Transport Layer (eg TCP protocol) Internet Layer
There are other protocols that work differently Transport Layer (eg TCP protocol) Part of operating system Ensuring sequence of packets in a message all arrive in order Protocol to acknowledge, recover, resend, reorder. Internet Layer Network Access Layer

11 TCP/IP Stack Application Layer Transport Layer Internet Layer
Programs that need to communicate - Clients and Servers Only need to understand part of the Transport layer Transport Layer Internet Layer Network Access Layer

12 Application Layer view
Applications that want to communication with other applications on another computer can use TCP scokets. TCP (Transport Layer) provides “Sockets”: A socket is one end of a TCP connection A scotet has two streams associated with it: Input stream (from the other end of the connection) Application can read from it Output stream (to the other end of the connection) Application can write/print to it Scoket

13 Getting a Socket Connection requires each computer to set up a socket connected to the other How do you specify where you want the connection to go to? Which program running on which computer is going to server you a web page? Which computer sets up a socket first? Do you need a socket at the other end before you set up yours?

14 Addressing a connection
Two parts to the address: host computer: IP address, or Host name “port” (an integer) Each computer on the network must have an IP address or “debretts.ecs.vuw.ac.nz” Operating system provides a set of “ports” that connections can be associated with. Type echo $HOSTNAME in a terminal to find your name and use this to connect to a service on your own computer. 1 2 : 80 6667

15 Who goes first? Client – Server model:
Server applications can run on a remote host Server application listens on a known port Client application requests a connection to host : port Server applications accept the request Operating systems will set up a new socket on each end with a connection between them. A Java ServerSocket only needs a port number; A Java Socket needs a port number and the IP or host name of the computer the server is running on. Setup the Server before the Client

16 Using sockets in Java Sockets provide streames that are easy to use!
Streams are sequences of characters Like files, or UI text pane, or System.in/System.out try { Socket socket = get a socket somehow ; Scanner inputFromTarget = new Scanner(socket.getInputStream()); PrintStream outputToTarget = new Scanner(socket.getOutputStream()); while (inputFromTarget.hasNext()){ String line = inputFromTarget.nextLine(); String response = work out a response ; outputToTarget.println(response); flush(response); } } catch (IOException e){System.out.println(“connection failure ”+e); }

17 Addressing a connection
Host1 1 2 : 80 6667 Host2 1 2 : 80 6667 xx xx Server Listens on port 6667 Client request connection to port 6667 on Host2 port xx is not specified Server accepts connection OS creates socket connected to port xx on Host1 OS creates socket connected to port 6667 on Host2 Server is still listening!

18 Setting up the sockets Server
try { ServerSocket serverSocket = new ServerSocket(PORT); while (true) { Socket socket = serverSocket.accept(); … set up Scanner and PrintStream and communicate via socket } } catch (IOException e){System.out.println("Failed connection "+ e); } Socket socket = new Socket(("irc.ecs.vuw.ac.nz", PORT); …set up Scanner and PrintStream and communicate via socket Server port Server port Client


Download ppt "Networking COMP 112 2017."

Similar presentations


Ads by Google