gamnit :: RemoteServer :: _config
RemoteServerConfig
used to initiate connection to the server
gamnit :: RemoteServer :: _reader
MsgPackDeserializer
used to receive data from this client through socket
gamnit :: RemoteServer :: _socket
Communication socket with the servergamnit :: RemoteServer :: _writer
MsgPackSerializer
used to send data to this client through socket
gamnit :: RemoteServer :: config
RemoteServerConfig
used to initiate connection to the server
gamnit :: RemoteServer :: config=
RemoteServerConfig
used to initiate connection to the server
gamnit :: RemoteServer :: defaultinit
gamnit :: RemoteServer :: reader
MsgPackDeserializer
used to receive data from this client through socket
gamnit :: RemoteServer :: reader=
MsgPackDeserializer
used to receive data from this client through socket
gamnit :: RemoteServer :: socket
Communication socket with the servergamnit :: RemoteServer :: socket=
Communication socket with the servergamnit :: RemoteServer :: writer
MsgPackSerializer
used to send data to this client through socket
gamnit :: RemoteServer :: writer=
MsgPackSerializer
used to send data to this client through socket
gamnit $ RemoteServer :: SELF
Type of this instance, automatically specialized in every classgamnit :: RemoteServer :: _config
RemoteServerConfig
used to initiate connection to the server
gamnit :: RemoteServer :: _reader
MsgPackDeserializer
used to receive data from this client through socket
gamnit :: RemoteServer :: _socket
Communication socket with the servergamnit :: RemoteServer :: _writer
MsgPackSerializer
used to send data to this client through socket
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
gamnit :: RemoteServer :: config
RemoteServerConfig
used to initiate connection to the server
gamnit :: RemoteServer :: config=
RemoteServerConfig
used to initiate connection to the server
core :: Object :: defaultinit
gamnit :: RemoteServer :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).gamnit :: RemoteServer :: reader
MsgPackDeserializer
used to receive data from this client through socket
gamnit :: RemoteServer :: reader=
MsgPackDeserializer
used to receive data from this client through socket
gamnit :: RemoteServer :: socket
Communication socket with the servergamnit :: RemoteServer :: socket=
Communication socket with the servergamnit :: RemoteServer :: writer
MsgPackSerializer
used to send data to this client through socket
gamnit :: RemoteServer :: writer=
MsgPackSerializer
used to send data to this client through socket
# Connection to a remote server
class RemoteServer
# `RemoteServerConfig` used to initiate connection to the server
var config: RemoteServerConfig
# Communication socket with the server
var socket: nullable TCPStream = null
# Is this connection connected?
fun connected: Bool
do
var socket = socket
return socket != null and socket.connected
end
# `MsgPackSerializer` used to send data to this client through `socket`
var writer: MsgPackSerializer is noinit
# `MsgPackDeserializer` used to receive data from this client through `socket`
var reader: MsgPackDeserializer is noinit
# Attempt connection with the remote server
fun connect: Bool
do
print "Connecting to {config.address}:{config.port}..."
var socket = new TCPStream.connect(config.address.to_s, config.port)
self.socket = socket
if not socket.connected then
print "Connection failed: {socket.last_error or else "Internal error"}"
return false
end
# Setup serialization
writer = new MsgPackSerializer(socket)
writer.cache = new AsyncCache(false)
reader = new MsgPackDeserializer(socket)
writer.link reader
return true
end
# Attempt handshake with server
#
# Validates compatibility between `handshake_app_name` and `handshake_app_version`.
#
# On error, close `socket`.
fun handshake: Bool
do
# The client goes first so that the server doesn't show its hand
var socket = socket
assert socket != null
# App name
var app_name = sys.handshake_app_name
socket.serialize_msgpack app_name
var server_app = socket.deserialize_msgpack("String")
if server_app != app_name then
print_error "Handshake Error: server app name is '{server_app or else "<invalid>"}'"
socket.close
return false
end
# App version
socket.serialize_msgpack sys.handshake_app_version
var server_version = socket.deserialize_msgpack("String")
if server_version != sys.handshake_app_version then
print_error "Handshake Error: server version is different '{server_version or else "<invalid>"}'"
socket.close
return false
end
return true
end
end
lib/gamnit/network/client.nit:55,1--132,3