Project HomeDocument HomeContents
Library: (ypsilon socket)
This library provides an Internet socket interface.
Summaries:
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>
[Back] [Top]
Procedure: make-client-socket
make-client-socket returns a client socket connected to an Internet address.
syntax:
(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>
arguments:
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)
node
—a network address. (examples: "www.w3.org", "localhost", "128.30.52.45")
service
—a network service. (examples: "http", "ssh", "80", "22")
ai-family
—an address family specifier. Predefined specifiers are listed below:
AF_INET
AF_INET6
AF_UNSPEC
ai-socktype
—a socket type specifier. Predefined specifiers are listed below:
SOCK_STREAM
SOCK_DGRAM
SOCK_RAW
ai-flags
—an additional options specifier. Predefined specifiers are listed below:
AI_ADDRCONFIG
AI_ALL
AI_CANONNAME
AI_NUMERICHOST
AI_NUMERICSERV
AI_PASSIVE
AI_V4MAPPED
ai-protocol
—a protocol specifier. Predefined specifiers are listed below:
IPPROTO_TCP
IPPROTO_UDP
IPPROTO_RAW
description:
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
examples:
> (import (rnrs) (ypsilon socket))
> (make-client-socket "www.w3.org" "http")
#<client-socket tcp stream 128.30.52.38:80>
[Back] [Top]
Procedure: make-server-socket
make-server-socket returns a server socket waiting for connections.
syntax:
(make-server-socket service ai-family ai-socktype ai-protocol) => <server-socket>
arguments:
service:
ai-family:
ai-socktype:
ai-protocol:
<string>
<int>
<int>
<int>
 
(default: AF_INET)
(default: SOCK_STREAM)
(default: 0)
service
—a network service. (examples: "http", "telnet", "80", "23")
ai-family
—an address family specifier. Predefined specifiers are listed below:
AF_INET
AF_INET6
AF_UNSPEC
ai-socktype
—a socket type specifier. Predefined specifiers are listed below:
SOCK_STREAM
SOCK_DGRAM
SOCK_RAW
ai-protocol
—a protocol specifier. Predefined specifiers are listed below:
IPPROTO_TCP
IPPROTO_UDP
IPPROTO_RAW
description:
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
examples:
> (import (rnrs) (ypsilon socket))
> (make-server-socket "8080")
#<server-socket tcp stream 0.0.0.0:8080>
[Back] [Top]
Procedure: socket?
socket? returns #t if its argument is a socket, and otherwise returns #f.
syntax:
(socket? x) => <boolean>
arguments:
x:
<object>
[Back] [Top]
Procedure: socket-port
socket-port returns a fresh binary input/output port associated with a socket.
syntax:
(socket-port socket) => <port>
arguments:
socket:
<socket>
description:
A port returned by socket-port can be used as an ordinary port.
[Back] [Top]
Procedure: call-with-socket
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).
syntax:
(call-with-socket socket proc) => <object>
arguments:
socket:
proc:
<socket>
<procedure>
description:
If proc returns, socket is closed implicitly, and call-with-socket returns a value returned by proc.
[Back] [Top]
Procedure: shutdown-output-port
shutdown-output-port shutdowns output connection of a socket that associated with a port.
syntax:
(shutdown-output-port port) => unspecified
arguments:
port:
<port>
The port must be associated with a socket.
examples:
> (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
        :
        :
[Back] [Top]
Procedure: socket-accept
socket-accept wait for an incoming connection request, and returns a fresh connected client socket.
syntax:
(socket-accept socket) => <client-socket>
arguments:
socket:
<server-socket>
[Back] [Top]
Procedure: socket-send
socket-send sends a binary data block to a socket.
syntax:
(socket-send socket buffer flags) => unspecified
arguments:
socket:
buffer:
flags:
<socket>
<bytevector>
<int>
description:
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.
[Back] [Top]
Procedure: socket-recv
socket-recv receives a binary data block from a socket.
syntax:
(socket-recv socket flags) => <bytevector>
arguments:
socket:
flags:
<socket>
<int>
description:
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.
[Back] [Top]
Procedure: socket-shutdown
socket-shutdown shutdowns a socket.
syntax:
(socket-shutdown socket how) => unspecified
arguments:
socket:
how:
<socket>
SHUT_RD, SHUT_WR, or SHUT_RDWR
description:
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.
[Back] [Top]
Procedure: socket-close
socket-close closes a socket.
syntax:
(socket-close socket) => unspecified
arguments:
socket:
<socket>
[Back] [Top]
Constants:  AF_UNSPEC, AF_INET, AF_INET6
Each constant is defined to an exact integer value of a correspondent C header file definition.
[Back] [Top]
Constants:  SOCK_STREAM, SOCK_DGRAM, SOCK_RAW
Each constant is defined to an exact integer value of a correspondent C header file definition.
[Back] [Top]
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.
[Back] [Top]
Constants:  IPPROTO_TCP, IPPROTO_UDP, IPPROTO_RAW
Each constant is defined to an exact integer value of a correspondent C header file definition.
[Back] [Top]
Constants:  SHUT_RD, SHUT_WR, SHUT_RDWR
Each constant is defined to an exact integer value of a correspondent C header file definition.
[Back] [Top]
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.
[Back] [Top]
Identifiers exported from (ypsilon socket) library
Contexual list of all exports:
make-client-socket
make-server-socket
socket?
socket-port
call-with-socket
shutdown-output-port
socket-accept
socket-send
socket-recv
socket-shutdown
socket-close
AF_UNSPEC
AF_INET
AF_INET6
SOCK_STREAM
SOCK_DGRAM
SOCK_RAW
AI_ADDRCONFIG
AI_ALL
AI_CANONNAME
AI_NUMERICHOST
AI_NUMERICSERV
AI_PASSIVE
AI_V4MAPPED
IPPROTO_TCP
IPPROTO_UDP
IPPROTO_RAW
SHUT_RD
SHUT_WR
SHUT_RDWR
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
Alphabetical list of all exports:
AF_INET
AF_INET6
AF_UNSPEC
AI_ADDRCONFIG
AI_ALL
AI_CANONNAME
AI_NUMERICHOST
AI_NUMERICSERV
AI_PASSIVE
AI_V4MAPPED
IPPROTO_RAW
IPPROTO_TCP
IPPROTO_UDP
MSG_CONFIRM
MSG_CTRUNC
MSG_DONTROUTE
MSG_DONTWAIT
MSG_EOF
MSG_EOR
MSG_ERRQUEUE
MSG_FIN
MSG_MORE
MSG_NOSIGNAL
MSG_OOB
MSG_PEEK
MSG_PROBE
MSG_RST
MSG_SYN
MSG_TRUNC
MSG_WAITALL
SHUT_RD
SHUT_RDWR
SHUT_WR
SOCK_DGRAM
SOCK_RAW
SOCK_STREAM
call-with-socket
make-client-socket
make-server-socket
shutdown-output-port
socket-accept
socket-close
socket-port
socket-recv
socket-send
socket-shutdown
socket?
[Back] [Top]