Home | » | Java | » | Advance Java | » | Socket Programming | » | Sockets for TCP/IP |
---|
Sockets are used for making a Connection with a Server and in this after Making a Connection With a Server , The Server will Make the Packets by Dividing a Large data into the Small Packets. The Socket of Client is used to Connect With a Server and Socket of Server is used to Send the data to Client. JAVA Contains Socket Class For Making a Connection or for Sending the data from a Client to Server by using the TCP/IP Connection.
The Various Constructors of Socket Class are –Socket ( String HostName, int PortNumber) First Argument Specify the Name of Server and Second is the Port Number Which we wants to use.
ServerSocket(int PortNumber,int number ) The First Arguments Specify the Number of Port which will be used by Client to Make a Connection With a Server and Second Argument Specify the Number of Users those may Request to a Server at a Single Time.
Methods | Description |
---|---|
getPort() | Retrieves the Port Number which a Client has used . |
getInetAddress() | Gives Address of Host or Computer on The Network. |
getOutputStream() | Returns the Outputstream which Writes the data on the Socket. |
Close() | To Close the Socket after Transmission. |
Creating a Server Program
The Server program creates a server socket that can communicate with the client socket using TCP/IP. The TCPServer class creates a server socket by using an object of the ServerSocket class. The following program code shows how to use ServerSocket class to create a server socket:
Creating a Server SocketC:\>jdk1.4\bin>javac ServerSocketProgram.java
C:\>jdk1.4\bin>java ServerSocketProgram
Creating a Client Program
The client program creates a client socket that can communicate with the server socket using TCP/IP. The TCPClient class creates a client socket using an object of the socket class. The following program code show how to use the Socket class to create the client socket:
Creating a Client SocketC:\>jdk1.4\bin>javac ClientSocketProgram.java
C:\>jdk1.4\bin>appletviewer ClientSocketProgram.html
|
||
Download Complete Program |
Socket Programming
Sockets for TCP/IP | Sockets of UDP |
No comments:
Post a Comment