|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
waba.lang.Object | +--waba.io.Stream | +--waba.io.Socket
Socket is a TCP/IP network socket.
Under Java and Windows CE, if no network is present, the socket constructor may hang for an extended period of time due to the implementation of sockets in the underlying OS. This is a known problem.
Here is an example showing data being written and read from a socket:
Socket socket = new Socket("www.yahoo.com", 80); if (!socket.isOpen()) return; byte buf[] = new byte[10]; buf[0] = 3; buf[1] = 7; socket.writeBytes(buf, 0, 2); int count = socket.readBytes(buf, 0, 10); if (count == 10) ... socket.close();
Constructor Summary | |
Socket(String host,
int port)
Opens a socket. |
Method Summary | |
boolean |
close()
Closes the socket. |
boolean |
isOpen()
Returns true if the socket is open and false otherwise. |
int |
readBytes(byte[] buf,
int start,
int count)
Reads bytes from the socket into a byte array. |
boolean |
setReadTimeout(int millis)
Sets the timeout value for read operations. |
int |
writeBytes(byte[] buf,
int start,
int count)
Writes to the socket. |
Methods inherited from class waba.lang.Object |
toString |
Constructor Detail |
public Socket(String host, int port)
host
- the host name or IP address to connect toport
- the port number to connect toMethod Detail |
public boolean close()
public boolean isOpen()
public boolean setReadTimeout(int millis)
millis
- timeout in millisecondspublic int readBytes(byte[] buf, int start, int count)
buf
- the byte array to read data intostart
- the start position in the byte arraycount
- the number of bytes to readpublic int writeBytes(byte[] buf, int start, int count)
buf
- the byte array to write data fromstart
- the start position in the byte arraycount
- the number of bytes to write
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |