Eiffel Media API
Overview Cluster Class Classes Index      Previous Next      Top Features

em.network.multiplayer

Class EM_NET_PROTOCOL


Direct ancestors

EM_TIME_SINGLETON, EM_NETWORK_HELPER_FUNCTIONS, EM_NET_OBJECT_TYPES, EM_NETWORK_CONSTANTS

Creation

Features

Invariants

indexing

description

The protocol that is used for network communication.

This is the lowest layer in the MP framework, just on top of the
actual sockets.

Message format:

Header:
Message prefix: STRING, 5 bytes (see message_prefix)
Version: INTEGER_8, 1 byte (see version)
Time object: STRING

Data (may be repeated):
Object ID: INTEGER, 4 bytes
Data: STRING

Short:
[PREFIX|VERSION|[ID|DATA]*]

date

$Date: 2005/10/28 11:33:36 $

revision

$Revision: 1.26 $

class

EM_NET_PROTOCOL

inherit

EM_NETWORK_CONSTANTS

create

make

-- Initialize the protocol.

ensure
time_sync_agent_set: time_sync_agent /= Void
not_is_time_master: not is_time_master
max_serialization_byte_count_positive: max_serialization_byte_count.item > 0

feature -- Access

cr: INTEGER

-- Carriage return character code

-- (From EM_NETWORK_CONSTANTS)

in_addr_any: INTEGER

-- Used for listening on all network interfaces

-- (From EM_NETWORK_CONSTANTS)

in_addr_broadcast: INTEGER

-- Used as destination when sending a message to all clients
-- on a subnet that allows broadcasts

-- (From EM_NETWORK_CONSTANTS)

in_addr_unresolved: INTEGER

-- Used for listening on all network interfaces

-- (From EM_NETWORK_CONSTANTS)

lf: INTEGER

-- Line feed character code

-- (From EM_NETWORK_CONSTANTS)

max_port_number: INTEGER

-- Highest valid value for a socket port

-- (From EM_NETWORK_CONSTANTS)

max_udp_packet_size: INTEGER

-- Maximum size of a UDP packet

-- (From EM_NETWORK_CONSTANTS)

min_port_number: INTEGER

-- Lowest valid value for a socket port

-- (From EM_NETWORK_CONSTANTS)

max_serialization_byte_count: INTEGER_REF

-- max serialization count

-- (From EM_NETWORK_CONSTANTS)

set_max_serialization_byte_count (a_count: INTEGER)

-- Set max_serialization_count to a_count.
-- If UDP is used this value should be *less* than Max_udp_packet_size.

-- (From EM_NETWORK_CONSTANTS)

ensure
max_serialization_byte_count_set: max_serialization_byte_count.item = a_count

feature -- Element change

set_object_update_handler (a_handler: PROCEDURE[ANY,TUPLE[INTEGER,INTEGER,EM_NET_UNSERIALIZER]])

-- Set the handler that is called if updated data from a client arrived.
-- Arguments that are passed to the event handler:
-- time: INTEGER
-- object ID: INTEGER
-- serialized object: STRING

feature -- Receive

parse_packet (a_packet: EM_UDP_PACKET)

-- Parse client message and fire the object received event.

require
not_too_long_input: a_packet.item.count <= max_udp_packet_size

feature -- Send

create_packet (net_objects: DS_LINKED_LIST [EM_NET_OBJECT]; serializer: EM_NET_SERIALIZER)

-- Create a new message and make it available in last_message.

ensure
not_too_long_output: last_packet.item.count <= max_udp_packet_size

feature -- Time synchronisation

correction_factor: DOUBLE

-- Correction factor
-- How much weight do you want to give the new measured time compared to the old value?
-- Use a reasonable value in general not too big.
-- A value of 1 means that you well completely take the new measured time.
-- A value of 0 means that you don't give any value to the new measured time.

disable_time_sync

-- Disable time sync

require
not_already_disabled: is_time_sync_enabled
enable_time_sync

-- Enable time sync

require
a_time_sync_group_is_needed: time_sync_group /= Void
not_already_enabled: not is_time_sync_enabled
is_time_master: BOOLEAN

-- Is this a time master?
-- In a client/server architecture you may elect the server to the time master.

is_time_sync_enabled: BOOLEAN

-- Is time synchronisation enabled?

last_packet: EM_UDP_PACKET

-- Last UDP packet that was created by create_packet

on_time_sync_request (a_request: EM_NET_TIME_SYNC_REQUEST)

-- Time sync request event

require
a_request /= Void
on_time_sync_response (a_response: EM_NET_TIME_SYNC_RESPONSE)

-- Time sync response event

send_time_sync_request

-- Send a time sync request.
-- The request will be sent to the group which is set by the feature set_time_sync_group.

set_correction_factor (a_factor: DOUBLE)

-- set correction_factor to a_factor

require
a_factor_in_range: a_factor >=0 and a_factor <= 1
ensure
correction_factor_set: correction_factor = a_factor
set_is_time_master (a_value: BOOLEAN)

-- Set is_time_master to a_value

ensure
is_time_master_set: is_time_master = a_value
set_time_sync_frequency (a_period_in_ms: INTEGER)

--Sset time_sync_period to a_period_in_ms

require
a_positive_period: a_period_in_ms > 0
ensure
time_sync_period_set: time_sync_period = a_period_in_ms
set_time_sync_group (a_group: EM_NET_GROUP)

-- set time_sync_group to a_group

require
a_group_not_void: a_group /= Void
ensure
time_sync_group_set: time_sync_group = a_group
time: INTEGER

-- Time in miliseconds

time_sync_group: EM_NET_GROUP

-- Group used for time synchronisation.

time_sync_period: INTEGER

-- How many miliseconds should be waited until the next sync request is sent?

invariant

time_sync_enabled_needs_time_sync_group: is_time_sync_enabled implies (time_sync_group /= Void)

-- From ANY
reflexive_equality: standard_is_equal (Current)
reflexive_conformance: conforms_to (Current)

end