java.net
Class Socket
java.lang.Object
|
+--java.net.Socket
- public class Socket
- extends java.lang.Object
This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines.
It is done by encapsulating java.microedition.io.Connector.
|
Constructor Summary |
Socket(java.lang.String host,
int port)
Creates a stream socket and connects it to the specified port number on the named host.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Socket
public Socket(java.lang.String host,
int port)
throws IOException
- Creates a stream socket and connects it to the specified port number on the named host.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!! Method in J2SE is throws UnknownHostException also !!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- Parameters:
host - the host name.port - the port number.- Throws:
IOException - if an I/O error occurs when creating the socket.
getInputStream
public InputStream getInputStream()
throws IOException
- Returns an input stream for this socket.
- Returns:
- an output stream for writing bytes to this socket.
- Throws:
if - an I/O error occurs when creating the output stream.
getOutputStream
public OutputStream getOutputStream()
throws IOException
- Returns an output stream for this socket.
- Returns:
- an output stream for writing bytes to this socket.
- Throws:
an - output stream for writing bytes to this socket.
getPort
public int getPort()
- Returns the remote port to which this socket is connected.
- Returns:
- the remote port number to which this socket is connected.
close
public void close()
throws IOException
- Closes this socket.
- Throws:
IOException - if an I/O error occurs when closing this socket.