_ikram
Member
Reputation: 3
Offline
Posts: 65
Referrals: 0
|
 |
« on: August 05, 2009, 04:24:33 PM » |
|
[Lesson] The socket Class Alright, the Socket class represents a socket connection on a port by means of a special object called an object, im gona show you two diffrent java classes that are designed yo work with sockets.
The Socket Class This socket class is the class that represents a socket connection between two diffrent programs, these program dont even have to be in the same computer, thats how cool Sockets are. Infact any two computers that are connected to the internet can communicate with each other via a socket.
Here are the most common methods and contructors used in the socket class:
Constructor Socket() - Creats an unconnected socket
Socket() (InetAddress adress, int port() -Creates a socket and connects it to the specfied adress and port
Socket(String host, int port) -Creates a socket and connects it to the specfied host and port
Method
Void Close() -closes the socket
Void connect (InetSocketAddressendpoint) -Connects the socket to a specifed adress.
InetAddress getInetAddress() -Gets the adress in which the socket is connected to.
InetStream getInputStream() -Gets an input stream that can be used to recive data sent though this socket.
OutputStream getOutputStream() -Gets an output stream that can be used to send data via the socket.
int getPort() - this finds the port which the socket is connected to.
boolean isBound() -It shows if the socket is connected to the port or not
boolean isClosed() -Shows is socket is closed.
The scocket class has certain constructors as you can see above which allows you to connect tp a spefic address.
Ikram
|