Skip to content

Networking

Functions

Accept All New Connections

Accept new connections for all servers.

Return Type: Boolean

Signatures:

bool accept_all_new_connections()

Accept New Connection

Accept new connections for a server

Parameters:

NameTypeDescription
serverServer SocketThe server to check

Return Type: Boolean

Signatures:

bool accept_new_connection(server_socket server)

Broadcast Message

Broadcast Message

Broadcast a message to all connections of a server.

Parameters:

NameTypeDescription
a_msgStringThe message to send
svrServer SocketThe server to send the message to.

Signatures:

void broadcast_message(const string &a_msg, server_socket svr)

Broadcast Message

Broadcase a message to all of the connections.

Parameters:

NameTypeDescription
a_msgStringThe message to send

Signatures:

void broadcast_message(const string &a_msg)

Broadcast Message

Broadcast a message to all connections of a server.

Parameters:

NameTypeDescription
a_msgStringThe message to send
nameStringThe name of the server to send the message to.

Signatures:

void broadcast_message(const string &a_msg, const string &name)

Check Network Activity

Check network activity, looking for new connections and messages.

Signatures:

void check_network_activity()

Clear Messages

Clear Messages

Clear all of the messages from a server or connection with the supplied name.

Parameters:

NameTypeDescription
nameStringThe name of the connection or the server to clear.

Signatures:

void clear_messages(const string &name)

Clear Messages

Clear all of the messages from a connection.

Parameters:

NameTypeDescription
a_connectionConnectionThe connection

Signatures:

void clear_messages(connection a_connection)

Clear Messages

Clear all of the messages from a server.

Parameters:

NameTypeDescription
svrServer SocketThe server to clear the messages from

Signatures:

void clear_messages(server_socket svr)

Close All Connections

Close all of the connections you have opened. This does not close connections to servers.

Signatures:

void close_all_connections()

Close All Servers

Close all of the servers that are currently open.

Signatures:

void close_all_servers()

Close Connection

Close Connection

Close the connection

Parameters:

NameTypeDescription
a_connectionConnectionThe connection to close

Return Type: Boolean

Signatures:

bool close_connection(connection a_connection)

Close Connection

Close the connection

Parameters:

NameTypeDescription
nameStringThe name of the connection to close

Return Type: Boolean

Signatures:

bool close_connection(const string &name)

Close Message

Closes the message.

Parameters:

NameTypeDescription
msgMessageThe message to close

Signatures:

void close_message(message msg)

Close Server

Close Server

Closes the server with the indicated name.

Parameters:

NameTypeDescription
nameStringThe name of the server to close

Return Type: Boolean

Signatures:

bool close_server(const string &name)

Close Server

Closes the server, all connections with clients will be shut and the port will be closed.

Parameters:

NameTypeDescription
svrServer SocketThe server to close

Return Type: Boolean

Signatures:

bool close_server(server_socket svr)

Connection Count

Connection Count

Returns the number of clients connected to a server.

Parameters:

NameTypeDescription
nameStringThe name of the server to check

Return Type: Unsigned Integer

Signatures:

unsigned int connection_count(const string &name)

Connection Count

Returns the number of clients connected to a server.

Parameters:

NameTypeDescription
serverServer SocketThe server to check

Return Type: Unsigned Integer

Signatures:

unsigned int connection_count(server_socket server)

Connection Ip

Connection Ip

Gets the ip address of the passed in connection.

Parameters:

NameTypeDescription
a_connectionConnectionThe connection

Return Type: Unsigned Integer

Signatures:

unsigned int connection_ip(connection a_connection)

Connection Ip

Gets the ip address of the connection with the supplied name.

Parameters:

NameTypeDescription
nameStringThe name of the connection

Return Type: Unsigned Integer

Signatures:

unsigned int connection_ip(const string &name)

Connection Named

Fetch the connection with the indicated name.

Parameters:

NameTypeDescription
nameStringThe name of the connection to fetch

Return Type: Connection

Signatures:

connection connection_named(const string &name)

Connection Port

Connection Port

Gets the port of the connection.

Parameters:

NameTypeDescription
a_connectionConnectionThe connection

Return Type: undefined

Signatures:

unsigned short connection_port(connection a_connection)

Connection Port

Gets the part of the connection.

Parameters:

NameTypeDescription
nameStringThe name of the connection

Return Type: undefined

Signatures:

unsigned short connection_port(const string &name)

Create Server

Create Server

Creates a new TCP server that can accept connections from other programs.

Parameters:

NameTypeDescription
nameStringThe name used to access the Server in splashkit
portunsigned shortThe port that clients will use to connect to the server

Return Type: Server Socket

Signatures:

server_socket create_server(const string &name, unsigned short port)

Create Server

Creates a new server that can accept connections from other programs.

Parameters:

NameTypeDescription
nameStringThe name used to access the Server in splashkit
portunsigned shortThe port that clients will use to connect to the server
protocolConnection TypeThe protocol used by the server

Return Type: Server Socket

Signatures:

server_socket create_server(const string &name, unsigned short port, connection_type protocol)

Dec To Hex

Converts the supplied decimal integer into it’s hexadecimal representation. e.g. 0x7F000001 from 2130706433

Parameters:

NameTypeDescription
a_decunsigned intdecimal to be converted to a hexadecimal number string

Return Type: String

Signatures:

string dec_to_hex(unsigned int a_dec)

Fetch New Connection

Get the oldest new connections made to the server, and reduces the new connection count by 1.

Parameters:

NameTypeDescription
serverServer SocketThe server to check

Return Type: Connection

Signatures:

connection fetch_new_connection(server_socket server)

Has Connection

Does the connection with the supplied name exist?

Parameters:

NameTypeDescription
nameStringThe name of the connection to check.

Return Type: Boolean

Signatures:

bool has_connection(const string &name)

Has Messages

Has Messages

Checks if there are any messages waiting to be read.

Return Type: Boolean

Signatures:

bool has_messages()

Has Messages

Checks if a connection has messages waiting to be read.

Parameters:

NameTypeDescription
conConnectionThe connection

Return Type: Boolean

Signatures:

bool has_messages(connection con)

Has Messages

Checks if a server or connection has any messages.

Parameters:

NameTypeDescription
nameStringThe name of the server or connection to check.

Return Type: Boolean

Signatures:

bool has_messages(const string &name)

Has Messages

Checks if a server has any messages waiting to be read.

Parameters:

NameTypeDescription
svrServer SocketThe server to check

Return Type: Boolean

Signatures:

bool has_messages(server_socket svr)

Has New Connections

Checks if any of the servers have new connections.

Return Type: Boolean

Signatures:

bool has_new_connections()

Has Server

Checks if there is a server with the indicated name.

Parameters:

NameTypeDescription
nameStringThe name of the server to check

Return Type: Boolean

Signatures:

bool has_server(const string &name)

Hex Str To Ipv4

The supplied hexadecimal string is translated into ipv4 standard address string. Function handles hex strings starting with or without 0x. e.g. 127.0.0.1 from 0x7F000001

Parameters:

NameTypeDescription
a_hexStringhexadecimal ipv4 string to convert

Return Type: String

Signatures:

string hex_str_to_ipv4(const string &a_hex)

Hex To Dec String

The supplied hexadecimal string is converted into it’s decimal representation e.g. 7F into 127

Parameters:

NameTypeDescription
a_hexStringhexadecimal string to convert

Return Type: String

Signatures:

string hex_to_dec_string(const string &a_hex)

Ipv4 To Dec

Encodes the supplied ipv4 address string (in format X.X.X.X) into a single integer e.g. 127.0.0.1 into 2130706433

Parameters:

NameTypeDescription
a_ipStringipv4 address to encode

Return Type: Unsigned Integer

Signatures:

unsigned int ipv4_to_dec(const string &a_ip)

Ipv4 To Hex

Converts an ipv4 address into it’s hexadecimal representation e.g. 0x7F000001 from 127.0.0.1

Parameters:

NameTypeDescription
a_ipStringip address to convert

Return Type: String

Signatures:

string ipv4_to_hex(const string &a_ip)

Ipv4 To Str

Decodes the supplied unsigned 32 bit integer into it’s ipv4 address form e.g. 2130706433 into 127.0.0.1

Parameters:

NameTypeDescription
ipunsigned intinteger to be decoded

Return Type: String

Signatures:

string ipv4_to_str(unsigned int ip)

Is Connection Open

Is Connection Open

Checks if the connection currently is open.

Parameters:

NameTypeDescription
conConnectionThe connection

Return Type: Boolean

Signatures:

bool is_connection_open(connection con)

Is Connection Open

Checks if the connection with the supplied name currently is open.

Parameters:

NameTypeDescription
nameStringThe name of the connection

Return Type: Boolean

Signatures:

bool is_connection_open(const string &name)

Last Connection

Last Connection

Gets the last client that connected to a server.

Parameters:

NameTypeDescription
nameStringThe name of the server to check

Return Type: Connection

Signatures:

connection last_connection(const string &name)

Last Connection

Gets the last client that connected to a server.

Parameters:

NameTypeDescription
serverServer SocketThe server to check

Return Type: Connection

Signatures:

connection last_connection(server_socket server)

Message Connection

Returns the connection that sent a message.

Parameters:

NameTypeDescription
msgMessageThe message

Return Type: Connection

Signatures:

connection message_connection(message msg)

Message Count

Message Count

Returns the number of messages on a server.

Parameters:

NameTypeDescription
svrServer SocketThe server to check

Return Type: Unsigned Integer

Signatures:

unsigned int message_count(server_socket svr)

Message Count

Returns the number of messages on a connection.

Parameters:

NameTypeDescription
a_connectionConnectionThe connection

Return Type: Unsigned Integer

Signatures:

unsigned int message_count(connection a_connection)

Message Count

Returns the number of messages on a server or connection.

Parameters:

NameTypeDescription
nameStringThe name of the server or connection

Return Type: Unsigned Integer

Signatures:

unsigned int message_count(const string &name)

Message Data

Gets the body of a message as a string.

Parameters:

NameTypeDescription
msgMessageThe message to check

Return Type: String

Signatures:

string message_data(message msg)

Message Data Bytes

Gets the body of a message as a list of bytes.

Parameters:

NameTypeDescription
msgMessageThe message to check

Return Type: Vector

Signatures:

vector<int8_t> message_data_bytes(message msg)

Message Host

Returns the host who made the message.

Parameters:

NameTypeDescription
msgMessageThe message to check

Return Type: String

Signatures:

string message_host(message msg)

Message Port

Returns the port used to send a message.

Parameters:

NameTypeDescription
msgMessageThe message to check

Return Type: undefined

Signatures:

unsigned short message_port(message msg)

Message Protocol

Returns the protocol used to send a message.

Parameters:

NameTypeDescription
msgMessageThe message to check

Return Type: Connection Type

Signatures:

connection_type message_protocol(message msg)

My Ip

Returns the ipv4 string of the localhost loopback for the current computer.

Return Type: String

Signatures:

string my_ip()

Name For Connection

Returns the name SplashKit would use for a connection made to a server from a host to a port.

Parameters:

NameTypeDescription
hostStringThe host name
portunsigned intThe port

Return Type: String

Signatures:

string name_for_connection(const string host, const unsigned int port)

New Connection Count

Get the number of new connections made to the server. The count will increase as the server accepts new connections. The count decreases each time you fetch a new connection, or can be set to 0 if you reset the new connection count.

Parameters:

NameTypeDescription
serverServer SocketThe server to check

Return Type: Integer

Signatures:

int new_connection_count(server_socket server)

Open Connection

Open Connection

Opens a TCP connection to a server using the supplied details.

Parameters:

NameTypeDescription
nameStringThe name for the connection
hostStringThe address of the server
portunsigned shortThe server’s port

Return Type: Connection

Signatures:

connection open_connection(const string &name, const string &host, unsigned short port)

Open Connection

Opens a connection to a server using the supplied details.

Parameters:

NameTypeDescription
nameStringThe name for the connection
hostStringThe address of the server
portunsigned shortThe server’s port
protocolConnection TypeThe protocol used to connect to the server

Return Type: Connection

Signatures:

connection open_connection(const string &name, const string &host, unsigned short port, connection_type protocol)

Read Message

Read Message

Read a message from the network (from a server or connection).

Return Type: Message

Signatures:

message read_message()

Read Message

Reads the first message from the connection.

Parameters:

NameTypeDescription
a_connectionConnectionA connection

Return Type: Message

Signatures:

message read_message(connection a_connection)

Read Message

Reads the first message from a connection or server.

Parameters:

NameTypeDescription
nameStringThe name of a connection or server

Return Type: Message

Signatures:

message read_message(const string &name)

Read Message

Reads the first message from the server.

Parameters:

NameTypeDescription
svrServer SocketA server

Return Type: Message

Signatures:

message read_message(server_socket svr)

Read Message Data

Read Message Data

Read message data from a connection or server.

Parameters:

NameTypeDescription
nameStringThe name of the connection or server

Return Type: String

Signatures:

string read_message_data(const string &name)

Read Message Data

Read message data from a connection.

Parameters:

NameTypeDescription
a_connectionConnectionThe connection

Return Type: String

Signatures:

string read_message_data(connection a_connection)

Read Message Data

Read message data from a server.

Parameters:

NameTypeDescription
svrServer SocketThe server

Return Type: String

Signatures:

string read_message_data(server_socket svr)

Reconnect

Reconnect

Attempt to reconnect the connection.

Parameters:

NameTypeDescription
a_connectionConnectionThe connection to reconnect

Signatures:

void reconnect(connection a_connection)

Reconnect

Attempt to reconnect the connection.

Parameters:

NameTypeDescription
nameStringThe name of the connection to reconnect.

Signatures:

void reconnect(const string &name)

Release All Connections

Close and release the resources used by all of the connections.

Signatures:

void release_all_connections()

Reset New Connection Count

Allows you to reset the new connection count to 0. (The connections are kept)

Parameters:

NameTypeDescription
serverServer SocketThe server to check

Signatures:

void reset_new_connection_count(server_socket server)

Retrieve Connection

Retrieve Connection

Get a connection from the server.

Parameters:

NameTypeDescription
nameStringThe name of the server
idxIntegerThe index of the connection

Return Type: Connection

Signatures:

connection retrieve_connection(const string &name, int idx)

Retrieve Connection

Get a connection from the server.

Parameters:

NameTypeDescription
serverServer SocketThe server
idxIntegerThe index of the connection

Return Type: Connection

Signatures:

connection retrieve_connection(server_socket server, int idx)

Send Message To

Send Message To

Send a message to the connection.

Parameters:

NameTypeDescription
a_msgStringThe message to send
a_connectionConnectionThe connection to send the message to

Return Type: Boolean

Signatures:

bool send_message_to(const string &a_msg, connection a_connection)

Send Message To

Send a message to the connection with the given name.

Parameters:

NameTypeDescription
a_msgStringThe message to send
nameStringThe name of the connection to send the message to

Return Type: Boolean

Signatures:

bool send_message_to(const string &a_msg, const string &name)

Server Has New Connection

Server Has New Connection

Checks of there are new connections waiting for a server.

Parameters:

NameTypeDescription
nameStringThe name of the server to check

Return Type: Boolean

Signatures:

bool server_has_new_connection(const string &name)

Server Has New Connection

Checks of there are new connections waiting for a server.

Parameters:

NameTypeDescription
serverServer SocketThe server to check

Return Type: Boolean

Signatures:

bool server_has_new_connection(server_socket server)

Server Named

Gets the server with the indicated name.

Parameters:

NameTypeDescription
nameStringThe name of the server to get

Return Type: Server Socket

Signatures:

server_socket server_named(const string &name)

Set Udp Packet Size

Change the size of the UDP packets.

Parameters:

NameTypeDescription
udp_packet_sizeunsigned intThe new packet size.

Signatures:

void set_udp_packet_size(unsigned int udp_packet_size)

Udp Packet Size

Returns the size SplashKit is using for UDP packets.

Return Type: Unsigned Integer

Signatures:

unsigned int udp_packet_size()

Download Bitmap

Download an image from a web server and load it into SplashKit so that you can use it.

Parameters:

NameTypeDescription
nameStringThe name of the bitmap resource when it is loaded
urlStringThe URL path to the image resoure
portunsigned shortThe port to connect to on the server

Return Type: Bitmap

Signatures:

bitmap download_bitmap(const string &name, const string &url, unsigned short port)

Download Font

Download a font from a web server and load it into SplashKit so that you can use it.

Parameters:

NameTypeDescription
nameStringThe name of the font resource when it is loaded
urlStringThe URL path to the font resoure
portunsigned shortThe port to connect to on the server

Return Type: Font

Signatures:

font download_font(const string &name, const string &url, unsigned short port)

Download Music

Download a music file from a web server and load it into SplashKit so that you can use it.

Parameters:

NameTypeDescription
nameStringThe name of the music resource when it is loaded
urlStringThe URL path to the music resoure
portunsigned shortThe port to connect to on the server

Return Type: Music

Signatures:

music download_music(const string &name, const string &url, unsigned short port)

Download Sound Effect

Download a sound effect from a web server and load it into SplashKit so that you can use it.

Parameters:

NameTypeDescription
nameStringThe name of the sound effect resource when it is loaded
urlStringThe URL path to the sound effect resoure
portunsigned shortThe port to connect to on the server

Return Type: Sound Effect

Signatures:

sound_effect download_sound_effect(const string &name, const string &url, unsigned short port)

Free Response

Free the response resource.

Parameters:

NameTypeDescription
responseHttp ResponseThe response to free

Signatures:

void free_response(http_response response)

Http Get

Make a get request to access a resource on the internet.

Parameters:

NameTypeDescription
urlStringThe path to the resource, for example http://splashkit.io
portunsigned shortThe port on the server (80 for http, 443 for https)

Return Type: Http Response

Signatures:

http_response http_get(const string &url, unsigned short port)

Http Post

Http Post

Post the supplied information to the indicated url with the given headers.

Parameters:

NameTypeDescription
urlStringThe url of the server to post the data to
portunsigned shortThe port to connect to on the server
bodyStringThe body of the message to post
headersVectorThe headers of the request

Return Type: Http Response

Signatures:

http_response http_post(const string &url, unsigned short port, const string &body, const vector<string> &headers)

Http Post

Post the supplied information to the indicated url.

Parameters:

NameTypeDescription
urlStringThe url of the server to post the data to
portunsigned shortThe port to connect to on the server
bodyStringThe body of the message to post

Return Type: Http Response

Signatures:

http_response http_post(const string &url, unsigned short port, string body)

Http Response To String

Read the HTTP response and convert it to text

Parameters:

NameTypeDescription
responseHttp ResponseThe response from the server

Return Type: String

Signatures:

string http_response_to_string(http_response response)

Save Response To File

Save the HTTP response downloaded into a file.

Parameters:

NameTypeDescription
responseHttp ResponseThe response from the server
pathStringThe path to the file where the response should be saved

Signatures:

void save_response_to_file(http_response response, string path)

Has Incoming Requests

Returns true if the given web_sever has pending requests.

Parameters:

NameTypeDescription
serverWeb ServerThe Web Server to check for waiting requests.

Return Type: Boolean

Signatures:

bool has_incoming_requests(web_server server)

Is Delete Request For

Checks if a request wants to delete a given resource.

Parameters:

NameTypeDescription
requestHttp RequestThe request to check
pathStringThe resource/route path

Return Type: Boolean

Signatures:

bool is_delete_request_for(http_request request, const string &path)

Is Get Request For

Checks if a request wants to get a given resource.

Parameters:

NameTypeDescription
requestHttp RequestThe request to check
pathStringThe resource/route path

Return Type: Boolean

Signatures:

bool is_get_request_for(http_request request, const string &path)

Is Options Request For

Checks if a request wants to check options for given resource.

Parameters:

NameTypeDescription
requestHttp RequestThe request to check
pathStringThe resource/route path

Return Type: Boolean

Signatures:

bool is_options_request_for(http_request request, const string &path)

Is Post Request For

Checks if a request wants to create (post) a given resource.

Parameters:

NameTypeDescription
requestHttp RequestThe request to check
pathStringThe resource/route path

Return Type: Boolean

Signatures:

bool is_post_request_for(http_request request, const string &path)

Is Put Request For

Checks if a request wants to update (put) a given resource.

Parameters:

NameTypeDescription
requestHttp RequestThe request to check
pathStringThe resource/route path

Return Type: Boolean

Signatures:

bool is_put_request_for(http_request request, const string &path)

Is Request For

Checks if a request is after a given resource.

Parameters:

NameTypeDescription
requestHttp RequestThe request to check
methodHttp MethodThe kind of request
pathStringThe resource/route path

Return Type: Boolean

Signatures:

bool is_request_for(http_request request, http_method method, const string &path)

Is Trace Request For

Checks if a request wants to trace a given resource.

Parameters:

NameTypeDescription
requestHttp RequestThe request to check
pathStringThe resource/route path

Return Type: Boolean

Signatures:

bool is_trace_request_for(http_request request, const string &path)

Next Web Request

Returns the next request on a given Web Server instance

Parameters:

NameTypeDescription
serverWeb ServerThe Web Server to get the Http Request from.

Return Type: Http Request

Signatures:

http_request next_web_request(web_server server)

Request Body

Returns the body of the request.

Parameters:

NameTypeDescription
rHttp RequestA request object.

Return Type: String

Signatures:

string request_body(http_request r)

Request Has Query Parameter

Returns true if the parameter exists in the query string.

Parameters:

NameTypeDescription
rHttp RequestA request object.
nameStringThe name of the parameter to check

Return Type: Boolean

Signatures:

bool request_has_query_parameter(http_request r, const string &name)

Request Headers

Returns the headers of the request.

Parameters:

NameTypeDescription
rHttp RequestA request object.

Return Type: Vector

Signatures:

vector<string> request_headers(http_request r)

Request Method

Returns the HTTP method of the client request.

Parameters:

NameTypeDescription
rHttp RequestA request object.

Return Type: Http Method

Signatures:

http_method request_method(http_request r)

Request Query Parameter

Returns the value of a parameter from within the query string, or the supplied default if no matching parameter is found.

Parameters:

NameTypeDescription
rHttp RequestA request object.
nameStringThe name of the parameter to fetch
default_valueStringThe value to return if the named parameter is not in the query string.

Return Type: String

Signatures:

string request_query_parameter(http_request r, const string &name, const string &default_value)

Request Query String

Returns the URI query string of the client request.

Parameters:

NameTypeDescription
rHttp RequestA request object.

Return Type: String

Signatures:

string request_query_string(http_request r)

Request Uri

Returns the server URI of the client request.

Parameters:

NameTypeDescription
rHttp RequestA request object.

Return Type: String

Signatures:

string request_uri(http_request r)

Request Uri Stubs

Returns an array of strings representing each stub of the URI. For example a request sent to http://localhost:8080/names/0 returns… [“names”, “0”]

Parameters:

NameTypeDescription
rHttp RequestThe request for retrieving URI to split into stubs.

Return Type: Vector

Signatures:

vector<string> request_uri_stubs(http_request r)

Send Css File Response

Serves a css file to the given Http Request.

Parameters:

NameTypeDescription
rHttp RequestThe request which is asking for the resource.
filenameStringThe name of the file in Resources/server

Signatures:

void send_css_file_response(http_request r, const string &filename)

Send File Response

Serves a file to the given Http Request.

Parameters:

NameTypeDescription
rHttp RequestThe request which is asking for the resource.
filenameStringThe name of the file in Resources/server
content_typeStringThe type of content being send:

Signatures:

void send_file_response(http_request r, const string &filename, const string &content_type)

Send Html File Response

Serves a HTML file to the given Http Request.

Parameters:

NameTypeDescription
rHttp RequestThe request which is asking for the resource.
filenameStringThe name of the file in Resources/server

Signatures:

void send_html_file_response(http_request r, const string &filename)

Send Javascript File Response

Serves a javascript file to the given Http Request.

Parameters:

NameTypeDescription
rHttp RequestThe request which is asking for the resource.
filenameStringThe name of the file in Resources/server

Signatures:

void send_javascript_file_response(http_request r, const string &filename)

Send Response

Send Response

Sends a response with no content to a Http Request.

Parameters:

NameTypeDescription
rHttp RequestThe Http Request to send the response to

Signatures:

void send_response(http_request r)

Send Response

Sends a message to a given Http Request.

Parameters:

NameTypeDescription
rHttp RequestThe request to be sent.
messageStringThe message to be sent

Signatures:

void send_response(http_request r, const string &message)

Send Response

Sends a response code to a given Http Request.

Parameters:

NameTypeDescription
rHttp RequestThe Http Request to send the response to
codeHttp Status CodeThe [HTTP status code](See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) to be sent.

Signatures:

void send_response(http_request r, http_status_code code)

Send Response

Sends a message to a given Http Request with the specified content type.

Parameters:

NameTypeDescription
rHttp RequestThe Http Request to send the response to
codeHttp Status CodeThe [HTTP status code](See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) to be sent.
messageStringThe messsage, in the form of a Http Response, to be sent.

Signatures:

void send_response(http_request r, http_status_code code, const string &message)

Send Response

Sends a message to a given Http Request with the specified content type.

Parameters:

NameTypeDescription
rHttp RequestThe Http Request to send the response to
codeHttp Status CodeThe [HTTP status code](See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) to be sent.
messageStringThe messsage, in the form of a Http Response, to be sent.
content_typeStringThe content type of the response.

Signatures:

void send_response(http_request r, http_status_code code, const string &message, const string &content_type)

Send Response

Sends a message to a given Http Request with the specified content type.

Parameters:

NameTypeDescription
rHttp RequestThe Http Request to send the response to
codeHttp Status CodeThe [HTTP status code](See https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) to be sent.
messageStringThe messsage, in the form of a Http Response, to be sent.
content_typeStringThe content type of the response.
headersVectorThe response headers

Signatures:

void send_response(http_request r, http_status_code code, const string &message, const string &content_type, const vector<string> &headers)

Send Response

Send a JSON response to a given Http Request

Parameters:

NameTypeDescription
rHttp RequestThe request the response belongs to.
jJsonThe json to be sent.

Signatures:

void send_response(http_request r, json j)

Split Uri Stubs

Returns an array of strings representing each stub of the URI. For example a request sent to http://localhost:8080/names/0 returns… [“names”, “0”]

Parameters:

NameTypeDescription
uriStringThe URI to split into stubs.

Return Type: Vector

Signatures:

vector<string> split_uri_stubs(const string &uri)

Start Web Server

Start Web Server

Creates a new web server listening for connections on port 8080.

Return Type: Web Server

Signatures:

web_server start_web_server()

Start Web Server

Starts the web server on a given port number.

Parameters:

NameTypeDescription
portunsigned shortThe port number to connect through.

Return Type: Web Server

Signatures:

web_server start_web_server(unsigned short port)

Stop Web Server

Stops a given Web Server instance.

Parameters:

NameTypeDescription
serverWeb ServerThe server instance to stop.

Signatures:

void stop_web_server(web_server server)

Types

Connection

A connection represents the communication channel from a client going to a server. This can be used for the client and the server to send and receive messages.


Connection Type

ConstantValueDescription
TCPUses the TCP protocol. SplashKit can send messages of anysize, and repackage it from you at the other end. Messagesare reliably transferred.
UDPUses the UDP protocol. SplashKit will send messages of upto 1024 bytes (by default). You need to handle packaginganything larger than this.
UNKNOWNThe protocol is unknown, usually due to the connectionor server being invalid or closed.

The kind of protocol used for a server of connection.


Http Method

ConstantValueDescription
HTTP_GET_METHODA get method
HTTP_POST_METHODA post method
HTTP_PUT_METHODA put method
HTTP_DELETE_METHODA delete method
HTTP_OPTIONS_METHODAn options method
HTTP_TRACE_METHODA trace method
UNKNOWN_HTTP_METHODA method not recognised by SplashKit

The method token is used to indicate the kind of action to be performed on the server. See W3 specifications.


Http Request

The request contains the details of the resource the user is requesting.


Http Response

A HTTP response is a resource that comes back from a HTTP request. This may be the text related to a web page, or the data related to a resource. Once you have used the response, you need to make sure to call Free Response.


Message

A message contains data that has been transferred between a client connection and a server (or visa versa).


Server Socket

A server represents a network resource that clients can connect to. The server will receive messages from all of the client connections, and can be used to access the clients connected to the server.


Web Server

The web server is able to listen for incoming requests, and you can then provide the response.