Rafal B
|
Re: RE: Timer based program problem
|
Rafal B
06/09/2009 1:07 PM
post31253
|
Re: RE: Timer based program problem
Weijie Zhang ---> thank you, I found it and it looks like this is the program I've been looking for. Unfortunately, it's
quite complicated ;) like for me, at the class we haven't written such complex programs. For example, this is a program
which send messages from client to server:
#include <stdlib.h>
#include <sys/neutrino.h>
#define SIZE 32
struct {
int type;
char text[SIZE];
}
msg, rmsg;
main() {
int child, res,i,pid, status;
int chid,con;
//Utworzenie kanalu
chid = ChannelCreate(_NTO_CHF_DISCONNECT);
//Tworzenie procesu potomnego
if ((child = fork()) == 0) {
// Kod klienta ------------------------------------
printf("Proces potomny utworzony\n");
pid = getppid();
//Klient dolacza sie do kanalu chid procesu pid
con = ConnectAttach(0,pid,chid,0,0);
if(con>=0) {
printf("Proces potomny - polaczenie %d\n",con);
}
else {
perror("Polaczenie"); exit(1);
}
for(i=0; i<10; i++) {
sprintf(msg.text,"K - %d",i);
printf("Klient - wyslane: %s \n", msg.text);
MsgSend(con,&msg,sizeof(msg),&rmsg,sizeof(rmsg));
printf("Klient - odebrane: %s \n",rmsg.text);
sleep(1);
};
exit(0);
}
//Kod serwera ---------------------------------------
printf("Serwer startuje \n");
for(i=0; i<11; i++) {
pid = MsgReceive(chid,&msg,sizeof(msg),NULL);
printf("Serwer - odebrane %s \n", msg.text);
sprintf(msg.text,"potwierdzenie %d",i+1);
res = MsgReply(pid,0,&msg,sizeof(msg));
}
pid = wait(&status);
}
Anyway ;) - I need to modify time1.c program a little bit.
Once again, thanks.
Regards
|
|
|