Networking In java

Published on Slideshow
Static slideshow
Download PDF version
Download PDF version
Embed video
Share video
Ask about this video

Scene 1 (0s)

Networking In java. The term network programming refers to writing programs that execute across multiple devices (computers), in which the devices are all connected to each other using a network. The java.net package provides classes and interfaces used for writing the problem at hand..

Scene 2 (15s)

Sockets provide the communication mechanism between two computers using TCP The java.net.Socket class represents a socket(client side), and the java.net.ServerSocket class provides a mechanism for the server program to listen for clients and establish connections with them..

Scene 3 (30s)

Steps for TCP Connection. 1. The server instantiates a ServerSocket object, denoting which port number communication is to occur on. 2.The server invokes the accept() method of the ServerSocket class. This method waits until a client connects to the server on the given port..

Scene 4 (45s)

3. After the server is waiting, a client instantiates a Socket object , specifying the server name and the port number to connect to. 4.The constructor of the Socket class attempts to connect the client to the specified server and the port number. 5.On the server side, the accept() method returns a reference to a new socket on the server that is connected to the client's socket..

Scene 5 (1m 5s)

After the connections are established, communication can occur using I/O streams . Each socket has both an OutputStream and an InputStream. client's OutputStream is connected to the server's InputStream, and the client's InputStream is connected to the server's OutputStream..

Scene 6 (1m 20s)

ServerSocket Class Methods. public ServerSocket ( int port) throws IOException public ServerSocket ( int port, int backlog) throws IOException public ServerSocket ( int port, int backlog, InetAddress address) throws IOException public ServerSocket () throws IOException.

Scene 7 (1m 32s)

Some other methods. public int getLocalPort() public Socket accept() throws IOException public void setSoTimeout(int timeout) public void bind(SocketAddress host, int backlog).

Scene 8 (1m 42s)

Socket Class Methods. public Socket(String host, int port) throws UnknownHostException , IOException . public Socket( InetAddress host, int port) throws IOException public Socket(String host, int port, InetAddress localAddress , int localPort ) throws IOException ..

Scene 9 (1m 55s)

public Socket( InetAddress host, int port, InetAddress localAddress , int localPort ) throws IOException . public Socket () public void connect( SocketAddress host, int timeout) throws IOException public InetAddress getInetAddress () public int getPort () --remote machine public int getLocalPort () --local machine.

Scene 10 (2m 9s)

public SocketAddress getRemoteSocketAddress() public InputStream getInputStream() throws IOException public OutputStream getOutputStream() throws IOException public void close() throws IOException.