This library provides an Internet socket interface.
|
make-client-socket | Returns a client socket connected to an Internet address |
make-server-socket | Returns a server socket waiting for connections |
socket? | Returns #t if its argument is a socket, and otherwise returns #f |
socket-port | Returns a fresh binary input/output port associated with a socket |
call-with-socket | Calls a procedure with a socket as an argument |
shutdown-output-port | Shutdowns output connection of a socket that associated with a port |
socket-accept | Wait for an incoming connection request, and returns a fresh connected client socket |
socket-send | Sends a binary data block to a socket |
socket-recv | Receives a binary data block from a socket |
socket-shutdown | Shutdowns a socket |
socket-close | Closes a socket |
AF_UNSPEC | <constant> |
AF_INET | <constant> |
AF_INET6 | <constant> |
SOCK_STREAM | <constant> |
SOCK_DGRAM | <constant> |
SOCK_RAW | <constant> |
AI_ADDRCONFIG | <constant> |
AI_ALL | <constant> |
AI_CANONNAME | <constant> |
AI_NUMERICHOST | <constant> |
AI_NUMERICSERV | <constant> |
AI_PASSIVE | <constant> |
AI_V4MAPPED | <constant> |
IPPROTO_TCP | <constant> |
IPPROTO_UDP | <constant> |
IPPROTO_RAW | <constant> |
SHUT_RD | <constant> |
SHUT_WR | <constant> |
SHUT_RDWR | <constant> |
MSG_OOB | <constant> |
MSG_PEEK | <constant> |
MSG_DONTROUTE | <constant> |
MSG_CTRUNC | <constant> |
MSG_PROBE | <constant> |
MSG_TRUNC | <constant> |
MSG_DONTWAIT | <constant> |
MSG_EOR | <constant> |
MSG_WAITALL | <constant> |
MSG_FIN | <constant> |
MSG_SYN | <constant> |
MSG_CONFIRM | <constant> |
MSG_RST | <constant> |
MSG_ERRQUEUE | <constant> |
MSG_NOSIGNAL | <constant> |
MSG_MORE | <constant> |
MSG_EOF | <constant> |
make-client-socket returns a client socket connected to an Internet address.
|
(make-client-socket node service)
(make-client-socket node service ai-family)
(make-client-socket node service ai-family ai-socktype)
(make-client-socket node service ai-family ai-socktype ai-flags)
(make-client-socket node service ai-family ai-socktype ai-flags ai-protocol)
=> <client-socket>
|
node:
service:
ai-family:
ai-socktype:
ai-flags:
ai-protocol:
|
<string>
<string>
<int>
<int>
<int>
<int>
|
(default: AF_INET)
(default: SOCK_STREAM)
(default: AI_V4MAPPED + AI_ADDRCONFIG)
(default: 0)
|
The Internet address is identified by node and service. make-client-socket uses getaddrinfo(3) to look up it. The arguments node, service, ai-family, ai-socktype, ai-flags, and ai-protocol will be passed to getaddrinfo(3) as a correspondent parameter. Refer to getaddrinfo(3) manual page for details
|
> (import (rnrs) (ypsilon socket))
> (make-client-socket "www.w3.org" "http")
#<client-socket tcp stream 128.30.52.38:80>
|
make-server-socket returns a server socket waiting for connections.
|
(make-server-socket service ai-family ai-socktype ai-protocol)
=> <server-socket>
|
service:
ai-family:
ai-socktype:
ai-protocol:
|
<string>
<int>
<int>
<int>
|
(default: AF_INET)
(default: SOCK_STREAM)
(default: 0)
|
The arguments service, ai-family, ai-socktype, and ai-protocol will be passed to getaddrinfo(3) as a correspondent parameter to setup server socket. Refer to getaddrinfo(3) manual page for details
|
> (import (rnrs) (ypsilon socket))
> (make-server-socket "8080")
#<server-socket tcp stream 0.0.0.0:8080>
|
socket? returns #t if its argument is a socket, and otherwise returns #f.
|
(socket? x)
=> <boolean>
|
x:
|
<object>
|
socket-port returns a fresh binary input/output port associated with a socket.
|
(socket-port socket)
=> <port>
|
socket:
|
<socket>
|
A port returned by socket-port can be used as an ordinary port.
|
call-with-socket calls a procedure with a socket as an argument. This procedure has an analogy to call-with-port of (rnrs io ports).
|
(call-with-socket socket proc)
=> <object>
|
socket:
proc:
|
<socket>
<procedure>
|
If proc returns, socket is closed implicitly, and call-with-socket returns a value returned by proc.
|
shutdown-output-port shutdowns output connection of a socket that associated with a port.
|
(shutdown-output-port port)
=> unspecified
|
port:
|
<port>
|
The port must be associated with a socket.
|
> (import (rnrs) (ypsilon socket))
> (call-with-socket
(make-client-socket "www.w3.org" "http")
(lambda (socket)
(call-with-port
(transcoded-port (socket-port socket)
(make-transcoder (utf-8-codec)
(eol-style none)))
(lambda (port)
(put-string port "GET / HTTP/1.1\r\n")
(put-string port "HOST: www.w3.org\r\n")
(put-string port "\r\n")
(shutdown-output-port port)
(display (get-string-all port))))))
HTTP/1.1 200 OK
Date: Thu, 29 Jan 2009 11:18:38 GMT
Server: Apache/2
Content-Location: Home.html
Vary: negotiate,accept
:
:
|
socket-accept wait for an incoming connection request, and returns a fresh connected client socket.
|
(socket-accept socket)
=> <client-socket>
|
socket:
|
<server-socket>
|
socket-send sends a binary data block to a socket.
|
(socket-send socket buffer flags)
=> unspecified
|
socket:
buffer:
flags:
|
<socket>
<bytevector>
<int>
|
socket-send uses send(2) to send data. The arguments flags will be passed to send(2) as a correspondent parameter. Refer to send(2) manual page for details.
|
socket-recv receives a binary data block from a socket.
|
(socket-recv socket flags)
=> <bytevector>
|
socket:
flags:
|
<socket>
<int>
|
socket-recv uses recv(2) to receive data. The arguments flags will be passed to recv(2) as a correspondent parameter. Refer to recv(2) manual page for details.
|
socket-shutdown shutdowns a socket.
|
(socket-shutdown socket how)
=> unspecified
|
socket:
how:
|
<socket>
SHUT_RD, SHUT_WR, or SHUT_RDWR
|
If how is SHUT_RD, a input is shutdowned.
If how is SHUT_WR, an output is shutdowned.
If how is SHUT_RDWR, both input and output are shutdowned.
|
socket-close closes a socket.
|
(socket-close socket)
=> unspecified
|
socket:
|
<socket>
|
Constants: | AF_UNSPEC, AF_INET, AF_INET6 |
Each constant is defined to an exact integer value of a correspondent C header file definition.
|
Constants: | SOCK_STREAM, SOCK_DGRAM, SOCK_RAW |
Each constant is defined to an exact integer value of a correspondent C header file definition.
|
Constants: | AI_ADDRCONFIG, AI_ALL, AI_CANONNAME, AI_NUMERICHOST, AI_NUMERICSERV, AI_PASSIVE, AI_V4MAPPED |
Each constant is defined to an exact integer value of a correspondent C header file definition.
|
Constants: | IPPROTO_TCP, IPPROTO_UDP, IPPROTO_RAW |
Each constant is defined to an exact integer value of a correspondent C header file definition.
|
Constants: | SHUT_RD, SHUT_WR, SHUT_RDWR |
Each constant is defined to an exact integer value of a correspondent C header file definition.
|
Constants: | MSG_OOB, MSG_PEEK, MSG_DONTROUTE, MSG_CTRUNC, MSG_PROBE, MSG_TRUNC, MSG_DONTWAIT, MSG_EOR, MSG_WAITALL, MSG_FIN, MSG_SYN, MSG_CONFIRM, MSG_RST, MSG_ERRQUEUE, MSG_NOSIGNAL, MSG_MORE, MSG_EOF |
Each constant is defined to an exact integer value of a correspondent C header file definition.
|