-
Notifications
You must be signed in to change notification settings - Fork 2
WebSocket
-
enum class Mode { NONE = -1, CLIENT = 0, SERVER }
-
using headers_t =
std::vector<std::pair<std::string, std::string>>
Type representing each header after the 2nd line of the opening handshake.
std::vector has the following structure std::pair as its values.- first: header name
- second: value
-
using handshake_t =
std::pair<std::string, headers_t>
opening handshake type- first: 1st line. i.e. the request line or the status line. it does not include "\r\n"
- second: headers_t
default constructor
move constructor
constructor that is Mode specify
- [in] mode: specify WebSocket::Mode
destructor
- return: reference of *this
bind addresses that uri specify. this use getaddrinfo(3) for specified uri, then open sockets and bind addresses
-
[in] uri: WebSocket URI
uri ::= "ws://" host (":" port)? path ("?" query)?
host ::= hostname | IPv4_dot_decimal | IPv6_colon_hexfor example ws://aa.bb.cc.dd aa.bb.cc.dd is a host name and a domain name. This pattern is that use each IPv4 and IPv6. ws://aa.bb.cc.dd:8080 ws://10.20.30.40 This pattern is that use only IPv4. ws://10.20.30.40:8080 ws://0.0.0.0 This pattern is that use IPv4 any address. ws://127.0.0.1 This pattern is that use only IPv4 loopback address. ws://2001::40 This pattern is that use only IPv6. ws://[2001::300:40]:8080 ws://::0 This pattern is that use IPv6 any address. ws://::1 This pattern is that use only IPv6 loopback address. -
return: reference of *this
-
exceptions: CRegexException, GetaddrinfoException, LwsockExrepss
bind address that uri specify. if you use hostname for uri and want to specify IPv4 or IPv6, you should use this method.
- [in] uri: WebSocket URI
- [in] af: AF_INET or AF_INET6 if you want to specify that use IPv4 or IPv6 then you set this param.
- return: reference of *this
- exceptions: CRegexException, GetaddrinfoException, LwsockExrepss
listen(2) each binded sockfds.
- [in] backlog: listen(2)'s backlog
- return: reference of *this
- exceptions: SystemErrorException
accept(2) socket
- return: a new WebSocket instance
- exceptions: LwsockException, SystemErrorException
accept(2) socket
- [out] remote: this is set in with the address of the peer socket
- return: a new WebSocket instance
- exceptions: LwsockException, SystemErrorException
receive a opening handshake request message. blocking recevie
- return: received handshake message parameters
- exceptions: CRegexException, LwsockExrepss, SystemErrorException
receive a opening handshake request message with timeout. blocking recevie.
recv_req internally calls recv(2) multiple times. timeout is effective that times.
- [in] timeout: specify timeout. Timespec instance
- return: received handshake message parameters
- exceptions: CRegexException, LwsockExrepss, SystemErrorException
send an opening handshake response message.
send default headers. they are Host, Upgrade, Connection, Sec-WebSocket-Key and Sec-WebSocket-Accept.
- return: sent a message
- exceptions: SystemErrorException
send an opening handshake response message.
if you want to send that add other headers to default headers, then use this api.
- [in] otherheaders: other headers
- return: sent a message
- exceptions: SystemErrorException
send an opening handshake response message that is set completely manual.
- [in] handshake: handshake message parameters
- return: sent a message
- exceptions: SystemErrorException
connect to the WebSocket server
-
[in] uri: WebSocket URI
uri ::= "ws://" host (":" port)? path ("?" query)?
host ::= hostname | IPv4_dot_decimal | IPv6_colon_hexfor example ws://aa.bb.cc.dd This pattern is that try IPv4 and IPv6. ws://aa.bb.cc.dd:8080 ws://10.20.30.40 This pattern is that try only IPv4. ws://10.20.30.40:8080 ws://127.0.0.1 This pattern is that try only IPv4 loopback address. ws://2001::40 This pattern is that try only IPv6. ws://[2001::300:40]:8080 ws://::1 This pattern is that try only IPv6 loopback address. -
return: reference of *this
-
exception: CRegexException, GetaddrinfoException, LwsockExrepss, SystemErrorException
connect to the server with timeout
-
[in] uri: WebSocket URI
uri ::= "ws://" host (":" port)? path ("?" query)?
host ::= hostname | IPv4_dot_decimal | IPv6_colon_hexfor example ws://aa.bb.cc.dd This pattern is that try IPv4 and IPv6. ws://aa.bb.cc.dd:8080 ws://10.20.30.40 This pattern is that try only IPv4. ws://10.20.30.40:8080 ws://127.0.0.1 This pattern is that try only IPv4 loopback address. ws://2001::40 This pattern is that try only IPv6. ws://[2001::300:40]:8080 ws://::1 This pattern is that try only IPv6 loopback address. -
[in] timeout: specify timeout. Timespec instance
-
return: reference of *this
-
exception: CRegexException, GetaddrinfoException, LwsockExrepss, SystemErrorException
connect to the server with timeout. and if you use hostname for uri and want to specify IPv4 or IPv6, you should use this method.
-
[in] uri: WebSocket URI.
for example ws://aa.bb.cc.dd ws://aa.bb.cc.dd:8080 -
[in] af: AF_INET or AF_INET6
if you want to specify that use IPv4 or IPv6 then you set this param. -
[in] timeout: specify timeout. Timespec instance
-
exception: CRegexException, GetaddrinfoException, LwsockExrepss, SystemErrorException
send an opening handshake request message.
- return: sent a message
send an opening handshake request message with other headers.
- [in] otherheaders: other headers
- return: sent a message
send an opening handshake request message that is set completely manual.
- [in] handshake: handshake message parameters
- return: sent a message
receive an opening handshake response message.
- return: pair
- first: received handshake message parameters
- second: status code of the 1st line
receive an opening handshake response message with timeout
- [in] timeout: specify timeout. Timespec instance
- return: pair
- first: received handshake message parameters
- second: status code of the 1st line
send a websocket text message to the remote
- [in] payload_data: WebSocket payload data
- return: sent data size. bytes
send a websocket binary message to the remote
- [in] payload_data: WebSocket payload data
- return: sent data size. bytes
send a websocket binary message to the remote
- [in] payload_data: WebSocket payload data
- return: sent data size. bytes
receive a websocket text message from the remote
- return: pair
- first: a received string message
- second: status code when recieved a CLOSE
receive a websocket text message from the remote with timeout
- [in] timeout: specify timeout. Timespec instance
- return: pair
- first: a received string message
- second: status code when recieved a CLOSE
receive a websocket binary message from the remote.
- return: pair
- first: a received binary message
- second: status code when recieved a CLOSE
receive a websocket binary message from the remote with timeout
- [in] timeout: specify timeout. Timespec instance
- return: pair
- first: a received binary message
- second: status code when recieved a CLOSE
send a PING frame
- return: sent data size. bytes
send a PING frame with a text app data.
- [in]: app_data: app data
- return: sent data size. bytes
send a PING frame with a binary app data.
- [in]: app_data: app data
- return: sent data size. bytes
send a PING frame with a binary app data.
- [in]: app_data: app data
- return: sent data size. bytes
send a PONG frame
- return: sent data size. bytes
send a PONG frame with a text app data.
- [in]: app_data: app data
- return: sent data size. bytes
send a PONG frame with a binary app data.
- [in]: app_data: app data
- return: sent data size. bytes
send a PONG frame with a binary app data.
- [in]: app_data: app data
- return: sent data size. bytes
send CLOSE frame, then wait a response (maybe CLOSE frame) or wait closing socket from the remote
- [in] status_code: status code
send CLOSE frame. send CLOSE frame, then wait a response (maybe CLOSE frame) or wait closing socket from the remote.
- [in] status_code: status code
- [in] reason: reason string
void WebSocket::send_close(const uint16_t status_code, const std::string& reason, const Timespec& timeout)
send CLOSE frame with timeout. send CLOSE frame, then wait a response (maybe CLOSE frame) or wait closing socket from the remote.
- [in] status_code: status code
- [in] reason: reason string
- [in] timeout: specify timeout. Timespec instance
get Sockaddr about the remote
- return: Sockaddr instance
get the request path.
- return: path (e.g. "/path/a/b/c")
get the request query parameters.
- return: query (e.g. "?aa=123&bb=xyz")
get the Origin header's value in the request headers, if client is a web browser.
- return: a value of Origin header.
get the raw sockfd that connected or accepted. you must not close socket.
- return: raw sockfd
get the raw sockfd that connected or accepted. you must close socket yourself.
- return: raw sockfd
get refernce binded sockfds
- return: reference of binded sockfds
set ostream for lwsock::WebSocket logs.
- [in] ost: ostream reference.
set ostream for WebSocket logs.
- [in] lvl: Log::Level
get WebSocekt log level
- return: Log::Level