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

em.network.classic

Class EM_UDP_SOCKET


Direct ancestors

EM_SOCKET, EM_NETWORK_CONSTANTS, EM_DELAYED_PROCEDURES, EM_SHARED_ERROR_HANDLER, NET2_FUNCTIONS_EXTERNAL

Known direct descendants

EM_NET_BASE

Creation

Features

Invariants

indexing

description

A specialized UDP socket that can be linked into the event loop such that
an event handler will be called if new incomming packets are detected.

date

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

revision

$Revision: 1.29 $

class

EM_UDP_SOCKET

inherit

EM_SOCKET
EM_DELAYED_PROCEDURES

create

make

-- Init

ensure
data_received_event_created: data_received_event /= Void

feature -- Initialization

make

-- Init

ensure
data_received_event_created: data_received_event /= Void

feature -- Access

network_subsystem: EM_NETWORK_SUBSYSTEM

-- EiffelMedia network subsystem is

-- (From EM_SHARED_SUBSYSTEMS)

ensure
network_subsystem_not_void: Result /= void
last_packet: EM_UDP_PACKET

-- Last received packet

port: INTEGER

-- Local socket port

-- (From EM_SOCKET)

timer: EM_TIME

-- Returns reference to the singleton

-- (From EM_TIME_SINGLETON)

ensure
time_not_void: Result /= Void

feature -- Status setting

close

-- Close the UDP socket.

-- (From EM_SOCKET)

require
network_enabled: Network_subsystem.is_enabled
open: is_open
ensure
closed: not is_open
open

-- Open UDP Socket on a_port.

-- (From EM_SOCKET)

require
network_enabled: Network_subsystem.is_enabled
closed: not is_open
port_set: 1024 < port and port < 65536
ensure then
open: is_open

feature -- Element change

set_port (a_port: INTEGER)

-- Set port to a_port.

-- (From EM_SOCKET)

require
a_port_in_range: 1024 < a_port and a_port < 65536
ensure
port_set: port = a_port

feature -- Basic operations

add_timed_procedure (a_procedure: PROCEDURE[ANY,TUPLE]; a_time_offset_in_ms: INTEGER)

-- Add a_procedure which will be called in TIME_OFFSET miliseconds from "now" in the same thread!
-- Use the feature "process" to call all procedures whose time is up.
-- You could use EM_TIME_SINGLETON for global timing: The EM_EVENT_LOOP will call "process" each loop once.
-- You can also use the EM_EVENT_LOOP to have a per scene executeion.

-- (From EM_DELAYED_PROCEDURES)

require
a_procedure /=Voida_time_offset_in_ms >= 0
process_timed_procedures_in_same_thread

-- executes all stored procedures whose time is up...
-- Make sure you don't add procedures which use a lot of computation time. Only small, short
-- procedures are appropriate. Otherwise use add_timed_callback which runs functions in a different thread
-- to avoid a laggy reaction to other events.

-- (From EM_DELAYED_PROCEDURES)

send (a_packet: EM_UDP_PACKET)

-- Send a_packet to its destination.

require
open: is_open
send_direct (a_destination: EM_INET_SOCKET_ADDRESS; a_string: STRING)

-- Send a_string to a_destination.

wipe_out_all_timed_procedures

-- clear the whole "delayed procedure call" list (procedures added with add_procedure, executed with execute)

-- (From EM_DELAYED_PROCEDURES)

feature -- Events

data_received_event: EM_EVENT_TYPE [TUPLE[EM_UDP_PACKET]]

-- Handle a received packet.

send_failed_event: EM_EVENT_TYPE [TUPLE [INTEGER]]

-- Send failed event.
-- Passed parameter is the error code: Em_error_resolve_ip or Em_error_send_failed

feature -- Setters

set_are_timed_procedures_paused (a_value: BOOLEAN)

-- Set are_timed_procedures_paused to a_value
-- Use this to pause the procedure callbacks. This is really usefull if you want to pause a game!
-- However, this will not pause functions added with add_timed_callback.

-- (From EM_DELAYED_PROCEDURES)

ensure
are_timed_procedures_paused_set: are_timed_procedures_paused = a_value

feature -- Status

is_open: BOOLEAN

-- Is socket open?

-- (From EM_SOCKET)

feature -- Attributes

are_timed_procedures_paused: BOOLEAN

-- Are timed prcedures paused?

-- (From EM_DELAYED_PROCEDURES)

feature {EM_SOCKETS} -- Implementation

handle_data_received

-- Handle data reveived event.

-- (From EM_SOCKET)

handle_send_failed (an_error: INTEGER)

-- Handle send failed.

net2_socket_id: INTEGER

-- Socket id of Net2

-- (From EM_SOCKET)

feature {NONE} -- Implementation

pause_start_ticks: INTEGER

-- pause started ticks
-- Used to compute a timedifference to implement pause mechanism.

-- (From EM_DELAYED_PROCEDURES)

procedure_list: DS_LINKED_LIST[EM_PAIR[PROCEDURE[ANY,TUPLE],INTEGER]]

-- list of procedures

-- (From EM_DELAYED_PROCEDURES)

invariant


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

end