Copyright ® (1997-2005) EDMGROUP Pty Ltd - EZY Prolog Reference

main page

EZY Socket Client

 

EZY Prolog provides simple way of creating client component of the client-server applications.

User socket_create to establish communication with remote server and associate connection with GUI element. EZY Prolog associates Windows sockets with GUI window.

This one-to-one association provides consistent conventions and simplifies GUI programming.

Socket client can initiate conversation with server by use of


 

Sample:

See ezy_socket_client.pro for more information how to program socket client.

% CREATE CONNECTION ON BUTTON PRESS

% READ SERVER NAME AND PORT AND

% ASSOCIATE CONNECTION WITH FRAME OBJECT client_panel

button_client_handler( _ ,e_control( _ , _ , BUTTON_OBJECT , _ )):-

ezy_object_name ( BUTTON_OBJECT , NAME ),

NAME = "Connect" ,

ezy_get_parent ( BUTTON_OBJECT , "client_panel" , WINDOW ),

SERVER_ADDR =[ "client_panel" , "server_name" ],

ezy_get_object ( WINDOW , SERVER_ADDR , SERVER_OBJECT ),

ezy_object_text ( SERVER_OBJECT , HOST_NAME ),

PORT_ADDR =[ "client_panel" , "port_number" ],

ezy_get_object ( WINDOW , PORT_ADDR , PORT_OBJECT ),

ezy_object_text ( PORT_OBJECT , PORT_STR ),

str_int ( PORT_STR , PORT ),

socket_create ( WINDOW , HOST_NAME , PORT , my_client_callback ),

! .

 

% Below is sample of the client event handler.

% For more information - please see ezy_socket_client.pro sample program

 

my_client_callback( _ , _ , server_finished , _ ):-

! ,

write ( "Server finished - stop message loop\n" ),

fail .

my_client_callback( WINDOW , _ ,server_stream( MESSAGE ), client_finished ):-

display_message( WINDOW , MESSAGE ),

! .

my_client_callback( WINDOW , _ ,server_error( MESSAGE ), client_finished ):-

format ( ERRMSG , "Connection Error: %\n" , MESSAGE ),

display_message( WINDOW , ERRMSG ),

! .

my_client_callback( WINDOW , _ ,server_reply( SERVER_REPLY ), client_finished ):-

display_message( WINDOW , SERVER_REPLY ),

display_message( WINDOW , "\n" ),

! .

my_client_callback( WINDOW , _ ,socket_closed( SOCKET , REASON ), client_finished ):-

format ( DATA_TO_DISPLAY , "Socket(%) closed: %s\n" , SOCKET , REASON ),

display_message( WINDOW , DATA_TO_DISPLAY ),

! .

my_client_callback( WINDOW , _ , server_ready , client_finished ):-

display_message( WINDOW , "Server ready message received\n" ),

! .

my_client_callback( WINDOW , SOCKET , REQUEST , REPLY ):-

REPLY = client_finished ,

write ( "my_client_callback(" , WINDOW , "," , SOCKET , "," , REQUEST , ")\n" ).

 

Copyright © 1997-2003 EDMGROUP (Australia)

Last Updated:

August 5, 2002