java.net
Class Socket
java.lang.Object
|
+--java.net.Socket
- public class Socket
- extends 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(String host,
int port)
Creates a stream socket and connects it to the specified port number on the named host. |
Method Summary |
void |
close()
Closes this socket. |
java.net.InputStream |
getInputStream()
Returns an input stream for this socket. |
java.net.OutputStream |
getOutputStream()
Returns an output stream for this socket. |
int |
getPort()
Returns the remote port to which this socket is connected. |
Socket
public Socket(String host,
int port)
throws java.net.IOException,
UnknownHostException
- Creates a stream socket and connects it to the specified port number on the named host.
- Parameters:
host
- the host name.port
- the port number.- Throws:
- java.net.IOException - if an I/O error occurs when creating the socket.
getInputStream
public java.net.InputStream getInputStream()
throws java.net.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 java.net.OutputStream getOutputStream()
throws java.net.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 java.net.IOException
- Closes this socket.
- Throws:
- java.net.IOException - if an I/O error occurs when closing this socket.