WebSocket++编程1

公共类型:

#include <connection.hpp>

Public Types

typedef connection< config > type
此连接的类型Type of this connection.
typedef lib::shared_ptr< type > ptr
指向此连接的共享指针的类型Type of a shared pointer to this connection.
typedef lib::weak_ptr< type > weak_ptr
指向此连接的弱指针的类型。Type of a weak pointer to this connection.
typedef config::concurrency_type concurrency_type
此连接的并发组件的类型。Type of the concurrency component of this connection.
typedef config::alog_type alog_type
访问日志策略类型。Type of the access logging policy.
typedef config::elog_type elog_type
错误日志记录策略的类型Type of the error logging policy.
typedef config::transport_type::transport_con_type transport_con_type
此连接的传输组件的类型。Type of the transport component of this connection.
typedef transport_con_type::ptr transport_con_ptr
指向此连接的传输组件的共享指针的类型。Type of a shared pointer to the transport component of this connection.
typedef lib::function< void(ptr)> termination_handler
typedef concurrency_type::scoped_lock_type scoped_lock_type
typedef concurrency_type::mutex_type mutex_type
typedef config::request_type request_type
typedef config::response_type response_type
typedef config::message_type message_type
typedef message_type::ptr message_ptr
typedef config::con_msg_manager_type con_msg_manager_type
typedef con_msg_manager_type::ptr con_msg_manager_ptr
typedef config::rng_type rng_type
Type of RNG.
typedef processor::processor< config > processor_type
typedef lib::shared_ptr< processor_type > processor_ptr
typedef lib::function< void(connection_hdl, message_ptr)> message_handler
typedef transport_con_type::timer_ptr timer_ptr
Type of a pointer to a transport timer handle.
typedef session::internal_state::value istate_type

Public Member Functions

 connection (bool p_is_server, std::string const &ua, const lib::shared_ptr< alog_type > &alog, const lib::shared_ptr< elog_type > &elog, rng_type &rng)
ptr get_shared ()
Get a shared pointer to this component.
void set_open_handler (open_handler h)
Set open handler. More...
void set_close_handler (close_handler h)
Set close handler. More...
void set_fail_handler (fail_handler h)
Set fail handler. More...
void set_ping_handler (ping_handler h)
Set ping handler. More...
void set_pong_handler (pong_handler h)
Set pong handler. More...
void set_pong_timeout_handler (pong_timeout_handler h)
Set pong timeout handler. More...
void set_interrupt_handler (interrupt_handler h)
Set interrupt handler. More...
void set_http_handler (http_handler h)
Set http handler. More...
void set_validate_handler (validate_handler h)
Set validate handler. More...
void set_message_handler (message_handler h)
Set message handler. More...
void set_open_handshake_timeout (long dur)
Set open handshake timeout. More...
void set_close_handshake_timeout (long dur)
Set close handshake timeout. More...
void set_pong_timeout (long dur)
Set pong timeout. More...
size_t get_max_message_size () const
Get maximum message size. More...
void set_max_message_size (size_t new_value)
Set maximum message size. More...
size_t get_max_http_body_size () const
Get maximum HTTP message body size. More...
void set_max_http_body_size (size_t new_value)
Set maximum HTTP message body size. More...
size_t get_buffered_amount () const
Get the size of the outgoing write buffer (in payload bytes) More...
size_t buffered_amount () const
Get the size of the outgoing write buffer (in payload bytes) More...
lib::error_code send (std::string const &payload, frame::opcode::value op=frame::opcode::text)
Create a message and then add it to the outgoing send queue. More...
lib::error_code send (void const *payload, size_t len, frame::opcode::value op=frame::opcode::binary)
Send a message (raw array overload) More...
lib::error_code send (message_ptr msg)
Add a message to the outgoing send queue. More...
lib::error_code interrupt ()
Asyncronously invoke handler::on_inturrupt. More...
void handle_interrupt ()
Transport inturrupt callback.
lib::error_code pause_reading ()
Pause reading of new data. More...
void handle_pause_reading ()
Pause reading callback. More...
lib::error_code resume_reading ()
Resume reading of new data. More...
void handle_resume_reading ()
Resume reading callback. More...
void ping (std::string const &payload)
Send a ping. More...
void ping (std::string const &payload, lib::error_code &ec)
exception free variant of ping
void handle_pong_timeout (std::string payload, lib::error_code const &ec)
Utility method that gets called back when the ping timer expires.
void pong (std::string const &payload)
Send a pong. More...
void pong (std::string const &payload, lib::error_code &ec)
exception free variant of pong
void close (close::status::value const code, std::string const &reason)
Close the connection. More...
void close (close::status::value const code, std::string const &reason, lib::error_code &ec)
exception free variant of close
bool get_secure () const
Returns the secure flag from the connection URI. More...
std::string const & get_host () const
Returns the host component of the connection URI. More...
std::string const & get_resource () const
Returns the resource component of the connection URI. More...
uint16_t get_port () const
Returns the port component of the connection URI. More...
uri_ptrget_uri () const
Gets the connection URI. More...
void set_uri (uri_ptr uri)
Sets the connection URI. More...
std::string const & get_subprotocol () const
Gets the negotated subprotocol. More...
std::vector< std::string > const & get_requested_subprotocols () const
Gets all of the subprotocols requested by the client. More...
void add_subprotocol (std::string const &request, lib::error_code &ec)
Adds the given subprotocol string to the request list (exception free) More...
void add_subprotocol (std::string const &request)
Adds the given subprotocol string to the request list (exception) More...
void select_subprotocol (std::string const &value, lib::error_code &ec)
Select a subprotocol to use (exception free) More...
void select_subprotocol (std::string const &value)
Select a subprotocol to use (exception) More...
std::string const & get_request_header (std::string const &key) const
Retrieve a request header. More...
std::string const & get_request_body () const
Retrieve a request body. More...
std::string const & get_response_header (std::string const &key) const
Retrieve a response header. More...
http::status_code::valueget_response_code () const
Get response HTTP status code. More...
std::string const & get_response_msg () const
Get response HTTP status message. More...
void set_status (http::status_code::value code, lib::error_code &ec)
Set response status code and message (exception free) More...
void set_status (http::status_code::value code)
Set response status code and message (exception) More...
void set_status (http::status_code::value code, std::string const &msg, lib::error_code &ec)
Set response status code and message (exception free) More...
void set_status (http::status_code::value code, std::string const &msg)
Set response status code and message (exception) More...
void set_body (std::string const &value, lib::error_code &ec)
Set response body content (exception free) More...
void set_body (std::string const &value)
Set response body content (exception) More...
void append_header (std::string const &key, std::string const &val, lib::error_code &ec)
Append a header (exception free) More...
void append_header (std::string const &key, std::string const &val)
Append a header (exception) More...
void replace_header (std::string const &key, std::string const &val, lib::error_code &ec)
Replace a header (exception free) More...
void replace_header (std::string const &key, std::string const &val)
Replace a header (exception) More...
void remove_header (std::string const &key, lib::error_code &ec)
Remove a header (exception free) More...
void remove_header (std::string const &key)
Remove a header (exception) More...
request_type const & get_request () const
Get request object. More...
response_type const & get_response () const
Get response object. More...
lib::error_code defer_http_response ()
Defer HTTP Response until later (Exception free) More...
void send_http_response (lib::error_code &ec)
Send deferred HTTP Response (exception free) More...
void send_http_response ()
Send deferred HTTP Response.
connection_hdlget_handle () const
Get Connection Handle. More...
bool is_server () const
Get whether or not this connection is part of a server or client. More...
std::string const & get_origin () const
Return the same origin policy origin value from the opening request. More...
session::state::value get_state () const
Return the connection state. More...
close::status::valueget_local_close_code () const
Get the WebSocket close code sent by this endpoint. More...
std::string const & get_local_close_reason () const
Get the WebSocket close reason sent by this endpoint. More...
close::status::valueget_remote_close_code () const
Get the WebSocket close code sent by the remote endpoint. More...
std::string const & get_remote_close_reason () const
Get the WebSocket close reason sent by the remote endpoint. More...
lib::error_code get_ec () const
Get the internal error code for a closed/failed connection. More...
message_ptr get_message (websocketpp::frame::opcode::value op, size_t size) const
Get a message buffer. More...
void read_handshake (size_t num_bytes)
void handle_read_handshake (lib::error_code const &ec, size_t bytes_transferred)
void handle_read_http_response (lib::error_code const &ec, size_t bytes_transferred)
void handle_write_http_response (lib::error_code const &ec)
void handle_send_http_request (lib::error_code const &ec)
void handle_open_handshake_timeout (lib::error_code const &ec)
void handle_close_handshake_timeout (lib::error_code const &ec)
void handle_read_frame (lib::error_code const &ec, size_t bytes_transferred)
void read_frame ()
Issue a new transport read unless reading is paused.
std::vector< int > const & get_supported_versions () const
Get array of WebSocket protocol versions that this connection supports.
void set_termination_handler (termination_handler new_handler)
void terminate (lib::error_code const &ec)
void handle_terminate (terminate_status tstat, lib::error_code const &ec)
void write_frame ()
Checks if there are frames in the send queue and if there are sends one. More...
void handle_write_frame (lib::error_code const &ec)
Process the results of a frame write operation and start the next write. More...
void start ()
Start the connection state machine.
void set_handle (connection_hdl hdl)
Set Connection Handle. More...
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot是一个用于创建独立的、基于Spring的应用程序的框架,它简化了Spring应用程序的配置和部署过程。Jetty是一个开源的Java HTTP服务器和Servlet容器,它支持WebSocket协议。WebSocket是一种在Web浏览器和服务器之间进行全双工通信的协议。 结合Spring Boot、Jetty和WebSocket,可以实现一个基于WebSocket的实时通信应用程序。下面是一个简单的介绍: 1. 首先,使用Spring Boot创建一个基本的Web应用程序。可以使用Spring Initializr来快速生成项目结构和依赖。 2. 在项目的依赖中添加Spring Boot和Jetty的相关依赖。例如,在pom.xml文件中添加以下依赖: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> ``` 3. 创建一个WebSocket处理器类,用于处理WebSocket连接和消息。可以使用Spring的`@Controller`注解和`@MessageMapping`注解来定义处理方法。 4. 在应用程序的配置类中,使用`@EnableWebSocket`注解启用WebSocket支持,并配置WebSocket处理器。 5. 运行应用程序,并通过WebSocket客户端连接到应用程序的WebSocket端点。可以使用JavaScript或其他编程语言来实现WebSocket客户端。 以上是一个简单的介绍,如果你对具体的实现细节或其他相关问题有进一步的了解,请告诉我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值