role IO::Socket
ErrorsCollection

role IO::Socket

Network socket

role IO::Socket { ... }

IO::Socket contains read and write methods for sockets. It is usually used through IO::Socket::INET.

Methods

method recv

method recv(IO::Socket:D: Cool $elems = Inf:$bin)

Receive a packet and return it, either as a Blob if :bin was passed, or a Str if not. Receives up to $elems or 65535 (whichever is smaller) bytes or characters.

Fails if the socket is not connected.

method read

method read(IO::Socket:D: Int(Cool$bytes)

Reads $bytes bytes from the socket and returns them in a Blob.

Fails if the socket is not connected.

routine get

method get(IO::Socket:D: --> Str:D)

Reads a single line of input from the socket, removing the trailing newline characters (as set by .nl-in). Returns Nil, if no more input is available.

Fails if the socket is not connected.

method print

method print(IO::Socket:D: Str(Cool$string)

Writes the supplied string to the socket, thus sending it to other end of the connection. The binary version is #method write.

Fails if the socket is not connected.

method write

method write(IO::Socket:D: Blob:D $buf)

Writes the supplied buffer to the socket, thus sending it to other end of the connection. The string version is #method print.

Fails if the socket is not connected.

method put

method put(IO::Socket:D: Str(Cool$string)

Writes the supplied string, with a \n appended to it, to the socket, thus sending it to other end of the connection.

Fails if the socket is not connected.

method close

method close(IO::Socket:D)

Closes the socket.

Fails if the socket is not connected.

method native-descriptor

method native-descriptor()

This returns a value that the operating system would understand as a "socket descriptor" and is suitable for passing to a native function that requires a socket descriptor as an argument such as setsockopt.