Socket
classin packageklyn.net
public class Socket implements AutoClosable
Socket
All Implemented Interfaces: AutoClosable

TCP client socket.

The socket uses blocking I/O.

Properties
Modifier and Type Member Description
public readonly property isConnected
isConnected as Boolean
Returns true when the socket has a valid native handle.
public readonly property reader
reader as SocketReader
Read-only property alias for getReader().
public readonly property remoteSocketAddress
remoteSocketAddress as SocketAddress
Returns the remote socket endpoint when known.
public readonly property writer
writer as SocketWriter
Read-only property alias for getWriter().
Constructors
Modifier and Type Member Description
public Socket Creates an unconnected socket.
public Socket
Socket(host as String, port as Int) throws IOException
Connects to the specified endpoint; an invalid endpoint is never treated as a request for an unconnected socket.
public Socket
Socket(host as String, port as Int, timeoutMillis as Int) throws IOException
Performs a network operation.
Methods
Modifier and Type Member Description
public override close
close() as Void throws IOException
Closes the socket.
public connect
connect(host as String, port as Int) as Void throws IOException
Connects this socket.
public connectWithTimeout
connectWithTimeout(host as String, port as Int, timeoutMillis as Int) as Void throws IOException
Performs a network operation.
public getInputStream
getInputStream() as SocketInputStream
Returns the input stream wrapper.
public getOutputStream
getOutputStream() as SocketOutputStream
Returns the output stream wrapper.
public getReader
getReader() as SocketReader
Returns a text reader facade over this socket.
public getWriter
getWriter() as SocketWriter
Returns a text writer facade over this socket.
public readAllText
readAllText() as String throws IOException
Reads the whole socket stream as text.
public readLine
readLine() as String throws IOException
Reads one line from the socket.
public receive
receive() as String throws IOException
Receives text data from the peer.
public receive
receive(maxBytes as Long) as String throws IOException
Receives text data from the peer.
public receiveBytes
receiveBytes(maxBytes as Long = 4096) as Byte[] throws IOException
Receives raw bytes from the peer.
public send
send(data as String) as Boolean throws IOException
Sends text data to the peer.
public sendBytes
sendBytes(data as Byte[]) as Int throws IOException
Sends raw bytes to the peer.
public setTimeoutMillis
setTimeoutMillis(timeoutMillis as Int) as Void throws IOException
Performs a network operation.
public write
write(readonly value as String) as Void throws IOException
Writes raw text to the socket.
public writeBytes
writeBytes(readonly value as Byte[]) as Void throws IOException
Writes raw bytes to the socket.
public writeLine
writeLine(readonly value as String) as Void throws IOException
Writes one line to the socket.
Inherited Methods
methodInherited Methods from AutoClosable: close