Skip navigation.
Home
The QNX Community Portal

View topic - I need Help, it´s urgent !!

I need Help, it´s urgent !!

Isn't the name clear?

I need Help, it´s urgent !!

Postby prinz » Tue Mar 24, 2009 11:43 am

Hello Guys,

I have this server program (see below) ans i have to make a graphic Client with phAB to communicate with the server.
when there is a connection between both, it has a display a container, if not , then simply an error message.

this is the server programm :
/*

* ResMgr and Message Server Process

*/



#include <stdio.h>

#include <unistd.h>

#include <stdlib.h>

#include <errno.h>

#include <string.h>

#include <sys/neutrino.h>

#include <sys/iofunc.h>

#include <sys/dispatch.h>

resmgr_connect_funcs_t ConnectFuncs;

resmgr_io_funcs_t IoFuncs;

iofunc_attr_t IoFuncAttr;


typedef struct

{

uint16_t msg_no;

char msg_data[255];

} server_msg_t;


int message_callback( message_context_t *ctp, int type, unsigned flags, void *handle )
//
{

server_msg_t *msg;

int num;

char msg_reply[255];

/* cast a pointer to the message data */

msg = (server_msg_t *)ctp->msg;

/* Print out some usefull information on the message */

printf( "\n\nServer hat die Nachricht bekommen:\n" );

printf( " type: %d\n" , type );

printf( " data: %s\n\n", msg->msg_data );

/* Build the reply message */

num = type - _IO_MAX;

snprintf( msg_reply, 254, "Server Got Message Code: _IO_MAX + %d", num );

/* Send a reply to the waiting (blocked) client */

MsgReply( ctp->rcvid, EOK, msg_reply, strlen( msg_reply ) + 1 );

return 0;
}

int main( int argc, char **argv )

{

resmgr_attr_t resmgr_attr;

message_attr_t message_attr;

dispatch_t *dpp;

dispatch_context_t *ctp, *ctp_ret;

int resmgr_id, message_id;

/* Create the Dispatch Interface */

dpp = dispatch_create();

if( dpp == NULL )

{

fprintf( stderr, "dispatch_create() failed: %s\n",

strerror( errno ) );

return EXIT_FAILURE;

}

memset( &resmgr_attr, 0, sizeof( resmgr_attr ) );

resmgr_attr.nparts_max = 1;

resmgr_attr.msg_max_size = 2048;

/* Setup the default I/O functions to handle open/read/write/... */

iofunc_func_init( _RESMGR_CONNECT_NFUNCS, &ConnectFuncs,

_RESMGR_IO_NFUNCS, &IoFuncs );

/* Setup the attribute for the entry in the filesystem */

iofunc_attr_init( &IoFuncAttr, S_IFNAM | 0666, 0, 0 );
resmgr_id = resmgr_attach( dpp, &resmgr_attr, "serv", _FTYPE_ANY,

0, &ConnectFuncs, &IoFuncs, &IoFuncAttr );

if( resmgr_id == -1 )

{

fprintf( stderr, "resmgr_attach() failed: %s\n", strerror( errno ) );

return EXIT_FAILURE;

}

/* Setup our message callback */

memset( &message_attr, 0, sizeof( message_attr ) );

message_attr.nparts_max = 1;

message_attr.msg_max_size = 4096;

/* Attach a callback (handler) for two message types */

message_id = message_attach( dpp, &message_attr, _IO_MAX + 1,

_IO_MAX + 2, message_callback, NULL );

if( message_id == -1 )

{

fprintf( stderr, "message_attach() failed: %s\n", strerror( errno ) );

return EXIT_FAILURE;

}

/* Setup a context for the dispatch layer to use */

ctp = dispatch_context_alloc( dpp );

if( ctp == NULL )

{

fprintf( stderr, "dispatch_context_alloc() failed: %s\n",

strerror( errno ) );

return EXIT_FAILURE;

}

/* The "Data Pump" - get and process messages */

while( 1 )

{

ctp_ret = dispatch_block( ctp );

if( ctp_ret )

{

dispatch_handler( ctp );

}

else

{

fprintf( stderr, "dispatch_block() failed: %s\n",

strerror( errno ) );

return EXIT_FAILURE;

}

}

return EXIT_SUCCESS;
}


Thank you in Advance
prinz
Active Member
 
Posts: 23
Joined: Tue Mar 24, 2009 11:37 am

RE: I need Help, it´s urgent !!

Postby micro » Tue Mar 24, 2009 1:13 pm

You´re welcome or is there a question?
micro
Senior Member
 
Posts: 458
Joined: Thu Jul 22, 2004 8:41 pm

Postby prinz » Tue Mar 24, 2009 3:16 pm

thx
I need help to write the client prog.
prinz
Active Member
 
Posts: 23
Joined: Tue Mar 24, 2009 11:37 am

Postby mario » Tue Mar 24, 2009 3:34 pm

The answer is in the documentation.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby prinz » Tue Mar 24, 2009 8:20 pm

Thx Mario, i won´t ask any question if i got no problem or if i didnt make some research.
i´m just new and i dont have much knowledge about QNX, only from the user Guide and the Programmers guide.
prinz
Active Member
 
Posts: 23
Joined: Tue Mar 24, 2009 11:37 am

Postby mario » Tue Mar 24, 2009 10:40 pm

Sorry if I came across a bit agressive. It`s just that there seems to be lots of people wanting the active poster here to do the work for them. Answer we give for free yet many are actually getting paid while they ask the question ;-)
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby prinz » Tue Mar 24, 2009 11:35 pm

i don´t want anyone to do this for me, i just asked for Help, and i´ll not get paid for this work coz its a school project :).
prinz
Active Member
 
Posts: 23
Joined: Tue Mar 24, 2009 11:37 am

Postby mario » Wed Mar 25, 2009 3:25 am

The call to resmgr_attach will create a path, serv in this case (don`t remember exactly where it will live in the path space ). Basically you will be able to open() this path. Via the file descriptor return by open, which will be -1 if the path doesn`t exists you can use MsgSend to send messages to the server. Hope that`s enough to get you going ;)
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 2 guests