8. Network socket library¶
The NETWORK module implements basic TCP socket listening server (currently only one connection). It would eventually be expanded to support client as well.
It its present form its used in Daslang Visual Studio Code plugin and upcoming debug server.
All functions and symbols are in “network” module, use require to get access to it.
require network
8.2. Classes¶
-
Server
¶
Single socket listener combined with single socket connection.
it defines as follows
_server : smart_ptr< network::NetworkServer >
-
Server.
make_server_adapter
(self: Server)¶
Creates new instance of the server adapter. Adapter is responsible for communicating with the Server class.
-
Server.
init
(self: Server; port: int const)¶
init returns bool
argument |
argument type |
---|---|
self |
|
port |
int const |
Initializes server with specific port
-
Server.
restore
(self: Server; shared_orphan: smart_ptr<NetworkServer>&)¶
argument |
argument type |
---|---|
self |
|
shared_orphan |
smart_ptr< network::NetworkServer >& |
Restore server state from after the context switch.
-
Server.
save
(self: Server; shared_orphan: smart_ptr<NetworkServer>&)¶
argument |
argument type |
---|---|
self |
|
shared_orphan |
smart_ptr< network::NetworkServer >& |
Saves server to orphaned state to support context switching and live reloading. The idea is that server is saved to the orphaned state, which is not part of the context state.
-
Server.
has_session
(self: Server)¶
has_session returns bool
Returns true if network session already exists. This is used to determine if the server should be initialized or not.
-
Server.
is_open
(self: Server)¶
is_open returns bool
Returns true if server is listening to the port.
-
Server.
is_connected
(self: Server)¶
is_connected returns bool
Returns true if server is connected to the client.
-
Server.
tick
(self: Server)¶
This needs to be called periodically to support the server communication and connections.
-
Server.
send
(self: Server; data: uint8? const; size: int const)¶
send returns bool
argument |
argument type |
---|---|
self |
|
data |
uint8? const |
size |
int const |
Send data.
-
Server.
onConnect
(self: Server)¶
This callback is called when server accepts the connection.
-
Server.
onDisconnect
(self: Server)¶
This callback is called when server or client drops the connection.
-
Server.
onData
(self: Server; buf: uint8? const; size: int const)¶
argument |
argument type |
---|---|
self |
|
buf |
uint8? const |
size |
int const |
This callback is called when data is received from the client.
-
Server.
onError
(self: Server; msg: string const; code: int const)¶
argument |
argument type |
---|---|
self |
|
msg |
string const |
code |
int const |
This callback is called on any error.
-
Server.
onLog
(self: Server; msg: string const)¶
argument |
argument type |
---|---|
self |
|
msg |
string const |
This is how server logs are printed.
8.3. Low lever NetworkServer IO¶
-
make_server
(class: void? const implicit; info: StructInfo const? const implicit)¶
make_server returns bool
argument |
argument type |
---|---|
class |
void? const implicit |
info |
rtti::StructInfo const? const implicit |
Creates new instance of the server.
-
server_init
(server: smart_ptr<NetworkServer> const implicit; port: int const)¶
server_init returns bool
argument |
argument type |
---|---|
server |
smart_ptr< network::NetworkServer > const implicit |
port |
int const |
Initializes server with given port.
-
server_is_open
(server: smart_ptr<NetworkServer> const implicit)¶
server_is_open returns bool
argument |
argument type |
---|---|
server |
smart_ptr< network::NetworkServer > const implicit |
Returns true if server is listening to the port.
-
server_is_connected
(server: smart_ptr<NetworkServer> const implicit)¶
server_is_connected returns bool
argument |
argument type |
---|---|
server |
smart_ptr< network::NetworkServer > const implicit |
Returns true if server is connected to the client.
-
server_tick
(server: smart_ptr<NetworkServer> const implicit)¶
argument |
argument type |
---|---|
server |
smart_ptr< network::NetworkServer > const implicit |
This needs to be called periodically for the server to work.
-
server_send
(server: smart_ptr<NetworkServer> const implicit; data: uint8? const implicit; size: int const)¶
server_send returns bool
argument |
argument type |
---|---|
server |
smart_ptr< network::NetworkServer > const implicit |
data |
uint8? const implicit |
size |
int const |
Sends data from server to the client.
-
server_restore
(server: smart_ptr<NetworkServer> const implicit; class: void? const implicit; info: StructInfo const? const implicit)¶
argument |
argument type |
---|---|
server |
smart_ptr< network::NetworkServer > const implicit |
class |
void? const implicit |
info |
rtti::StructInfo const? const implicit |
Restores server from orphaned state.