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

em.network.classic

Class EM_TCP_CLIENT_SOCKET


Direct ancestors

EM_SOCKET, EM_NETWORK_HELPER_FUNCTIONS, NET2_FUNCTIONS_EXTERNAL, STRING_HANDLER

Known direct descendants

EM_HTTP_PROTOCOL

Creation

Features

Invariants

indexing

description

A TCP client socket that can be connected to a remote host.
The remote host is identified by an EM_INET_SOCKET_ADDRESS which
can be set through set_hostname and set_port or set_address.

date

$Date$

revision

$Revision$

class

EM_TCP_CLIENT_SOCKET

inherit

EM_SOCKET
EM_NETWORK_HELPER_FUNCTIONS

create

make

-- Initialise socket with local address.

require
network_enabled: Network_subsystem.is_enabled
make_from_address (an_address: EM_INET_SOCKET_ADDRESS)

-- Initialise socket with an_address.

require
an_address_not_void: an_address /= Void

create {EM_SOCKETS}

make_from_socket_id (a_socket_id: like net2_socket_id)

-- Initialise socket with Net2 id a_socket_id in connected state.

ensure
connected: is_connected
net2_socket_id_set: net2_socket_id = a_socket_id

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)

network_subsystem: EM_NETWORK_SUBSYSTEM

-- EiffelMedia network subsystem is

-- (From EM_SHARED_SUBSYSTEMS)

ensure
network_subsystem_not_void: Result /= void
address: EM_INET_SOCKET_ADDRESS

-- Server address

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 -- Status report

is_trying_to_connect: BOOLEAN

-- Is socket trying to connect to server?

is_valid_ip_string (an_ip_string: STRING): BOOLEAN

-- Is an_ip_string a valid IP string?

-- (From EM_NETWORK_HELPER_FUNCTIONS)

require
an_ip_string_not_void: an_ip_string /= Void

feature -- Status setting

connect

-- Connect to server.

-- (From EM_SOCKET)

require
network_enabled: Network_subsystem.is_enabled
closed: not is_open
port_set: 1024 < port and port < 65536
require else
network_enabled: Network_subsystem.is_enabled
not_connected: not is_connected
ensure then
trying_to_connect: is_trying_to_connect
disconnect

-- Disconnect from server.

-- (From EM_SOCKET)

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

feature -- Element change

set_address (an_address: like address)

-- Set address to an_address.

require
not_connected: not is_connected
not_trying_to_connect: not is_trying_to_connect
an_address_not_void: an_address /= Void
ensure
address_set: address = an_address
set_host_ip (an_ip: INTEGER)

-- Set host ip of address.

require
not_connected: not is_connected
not_trying_to_connect: not is_trying_to_connect
ensure
host_ip_set: address.host_ip = an_ip
set_host_ip_as_string (an_ip_string: STRING)

-- Set host ip of address.
-- an_ip_string has to be in the format 'xy.xy.xy.xy'.

require
not_connected: not is_connected
not_trying_to_connect: not is_trying_to_connect
an_ip_string_not_void: an_ip_string /= Void
an_ip_string_valid: is_valid_ip_string (an_ip_string)
ensure
host_ip_set: address.host_ip = convert_ip_string_to_ip (an_ip_string)
set_hostname (a_hostname: STRING)

-- Set hostname of address.

require
not_connected: not is_connected
not_trying_to_connect: not is_trying_to_connect
a_hostname_not_void: a_hostname /= Void
a_hostname_not_empty: not a_hostname.is_empty
ensure
hostname_set: address.hostname.is_equal (a_hostname)
address_unresolved: not address.is_resolved
set_port (a_port: INTEGER)

-- Set port of address.

require
not_connected: not is_connected
not_trying_to_connect: not is_trying_to_connect
a_port_in_range: 0 < a_port and a_port < 65535
ensure
port_set: address.port = a_port

feature -- Conversion

convert_from_big_endian_16 (value: INTEGER): INTEGER

-- Convert a 16 bit value from network byte order (big endian) to the
-- byte order of this system.

-- (From EM_NETWORK_HELPER_FUNCTIONS)

convert_from_big_endian_32 (value: INTEGER): INTEGER

-- Convert a 32 bit value from network byte order (big endian) to the
-- byte order of this system.

-- (From EM_NETWORK_HELPER_FUNCTIONS)

convert_ip_string_to_ip (an_ip_string: STRING): INTEGER

-- Convert an_ip_string to an integer ip.

-- (From EM_NETWORK_HELPER_FUNCTIONS)

require
an_ip_string_not_void: an_ip_string /= Void
is_valid_ip_string: is_valid_ip_string(an_ip_string)
convert_to_big_endian_16 (value: INTEGER): INTEGER

-- Convert a 16 bit value from the byte order of the this system
-- to network byte order (big endian).

-- (From EM_NETWORK_HELPER_FUNCTIONS)

convert_to_big_endian_32 (value: INTEGER): INTEGER

-- Convert a 32 bit value from the byte order of the this system
-- to network byte order (big endian).

-- (From EM_NETWORK_HELPER_FUNCTIONS)

feature -- Basic operations

send_string (a_string: STRING)

-- Send a_string.

require
a_string_not_void: a_string /= Void
connected: is_connected

feature -- Events

connection_closed_event: EM_EVENT_TYPE [TUPLE []]

-- Connection closed event

connection_established_event: EM_EVENT_TYPE [TUPLE []]

-- Connected event

connection_failed_event: EM_EVENT_TYPE [TUPLE []]

-- Connection failed event

data_received_event: EM_EVENT_TYPE [TUPLE [STRING]]

-- Data received event

feature -- Status

is_connected: BOOLEAN

-- Is socket open?

-- (From EM_SOCKET)

feature {EM_SOCKETS} -- Implementation

handle_connection_closed

-- Handle connection closed.

handle_connection_established (a_socket_id: INTEGER)

-- Handle connection established.

ensure
socket_id_set: net2_socket_id = a_socket_id
connected: is_connected
handle_connection_failed (an_error: INTEGER)

-- Handle connection failed.

handle_data_received

-- Handle data received event.

-- (From EM_SOCKET)

net2_socket_id: INTEGER

-- Socket id of Net2

-- (From EM_SOCKET)

invariant

address_not_void: address /= Void
connection_established_event_not_void: connection_established_event /= Void
connection_closed_event_not_void: connection_closed_event /= Void
connection_failed_event_not_void: connection_failed_event /= Void
data_received_event_not_void: data_received_event /= Void
socket_id_consistent: is_connected implies net2_socket_id >= 0
socket_id_consistent: not is_connected implies net2_socket_id < 0

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

end