Property definitions

gamnit $ RemoteClient :: defaultinit
# Reference to a remote client connected to this server
class RemoteClient

	# Communication socket with the client
	var socket: TCPStream

	# Is this client connected?
	fun connected: Bool do return socket.connected

	# `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

	init
	do
		# Setup serialization
		writer = new MsgPackSerializer(socket)
		writer.cache = new AsyncCache(true)
		reader = new MsgPackDeserializer(socket)
		writer.link reader
	end

	# Check for compatibility with the client
	fun handshake: Bool
	do
		print "Server: Handshake initiated by {socket.address}"

		# Make sure it is the same app
		var server_app = sys.handshake_app_name
		var client_app = socket.deserialize_msgpack
		if server_app != client_app then
			print_error "Server Error: Client app name is '{client_app or else "<invalid>"}'"

			# Send an empty string so the client read it and give up
			socket.serialize_msgpack ""
			socket.close
			return false
		end

		socket.serialize_msgpack server_app

		# App version
		var app_version = sys.handshake_app_version
		var client_version = socket.deserialize_msgpack
		if client_version != app_version then
			print_error "Handshake Error: client version is different '{client_version or else "<invalid>"}'"
			socket.serialize_msgpack ""
			socket.close
			return false
		end

		socket.serialize_msgpack app_version

		return true
	end
end
lib/gamnit/network/server.nit:154,1--211,3