role IO::Socket
Network socket
1 | Methods |
1.1 | method recv |
1.2 | method read |
1.3 | routine get |
1.4 | method print |
1.5 | method write |
1.6 | method put |
1.7 | method close |
1.8 | method native-descriptor |
2 | Type Graph |
IO::Socket
contains read and write methods for sockets. It is usually used through IO::Socket::INET.
Methods
method recv
method recv(IO::Socket: Cool = Inf, :)
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: Int(Cool) )
Reads $bytes
bytes from the socket and returns them in a Blob.
Fails if the socket is not connected.
routine get
Defined as:
method get(IO::Socket: --> Str)
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: Str(Cool) )
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: Blob )
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: Str(Cool) )
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)
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
.