Download presentation
Presentation is loading. Please wait.
Published byLaureen Montgomery Modified over 6 years ago
2
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
PRESENTED To: Sir Abid……….! PRESENTED BY: Insharah khan………..! SUBJECT: *Programing * PRESENTATION TOPIC: * Network / Socket Programing *
4
Networking “A computer network is a set of two or more computers connected together in order to share information and other resources.” The computer in a network is connected with one another through cables, satellite or telephone lines. Essential components of every network system are *Hardware *Software *People It is also called information network.
5
Network topologies: “Physical layout or arrangement of connected devices in a network.”
7
To send and receive any kind of data or message it is necessary to have IP address of the sender and receiver.
10
Socket Programming: Sockets provide the communication mechanism between two computers using TCP. A client program creates a socket on its end of the communication and attempts to connect that socket to a server. When the connection is made, the server creates a socket object on its end of the communication. The client and server can now communicate by writing to and reading from the socket. After the connections are established, communication can occur using I/O streams. Each socket has both an OutputStream and an InputStream. The client's OutputStream is connected to the server's InputStream, and the client's InputStream is connected to the server's OutputStream. Two types of TCP sockets The java.net.Socket class represents a socket, It is used by a servers so that they can accept connection. and java.net.ServerSocket class provides a mechanism for the server program to listen for clients and establish connections with them.
11
ServerSocket Class Methods For Server
Socket Class Methods For Client Public Socket(InetAddress host, int port) throws IOException This method except that the host is denoted by an InetAddress object. public Socket(InetAddress host, int port, InetAddress localAddress, int localPort) Except that the host is denoted by an InetAddress object instead of a String public Socket(String host, int port) throws UnknownHostException, IOException. This method attempts to connect to the specified server at the specified port ServerSocket Class Methods For Server public ServerSocket(int port) throws IOException Attempts to create a server socket bound to the specified port. An exception occurs if the port is already bound by another application. public ServerSocket() Creates an unbound server socket. public ServerSocket(int port, int backlog) The backlog parameter specifies how many incoming clients to store in a wait queue.
12
Connects to a specified host over a specified port and prints out whatever is returned….!
13
import java. io. ; import java. net. ;
import java.io.*; import java.net.*; Request from Client to Server class ConnectDemo { Public static void main (String ars[]) { try { Socket s = new Socket (“ ” , 225); DataInputStream inp = new DataInputStream(s.getInputStream () ); Boolean more_data = true; System.out.println(“Established Connection”); while (more_data) { String line = inp.readLine(); if (line==null) more_data = false; else System.out.println(line); } } catch(IOException e) { System.out.print(“IO error” + e) } } }
14
import java. io. ; import java. net. ;
import java.io.*; import java.net.*; Server Response to Client class SimpleServer { public static void main (String args [ ] ) { try { ServerSocket sock = new ServerSocket(7500); Socket newsock = sock.accept ( ); DataInputStream inp = new DataInputStream(newsock . getInputStream ( ) ); PrintStream outp = new PrintStream( ) ; outp.Println(“hello : : enter QUIT to exit” ); Boolean more_data = true; while(more_data) { String line = inp.readLine( ) if (line = = null); more_data = false; else { outp.println ( “ From Server : ” + line + “ln” ) ; if (line. trim() . Equals ( “ QUIT ” ) ) more_data = false ; } } newsock.Close( ) ; }
15
Catch ( Exception e ) { System.out.print ( “IO error “ + e ) } } }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.