Romanof123 / document

0 stars 0 forks source link

Inter process Communication #5

Open Romanof123 opened 4 years ago

Romanof123 commented 4 years ago

IPC는 ?

qnx는 ipc를 뭘 지원하나?

messaging

clinet는?

Romanof123 commented 4 years ago

server create channel 사용법스?

Romanof123 commented 4 years ago

메세지 기타등등

Romanof123 commented 4 years ago

message test server code

////////////////////////////////////////////////////////////////////////////////
// server.c
//
// A QNX msg passing server.  It should receive a string from a client,
// calculate a checksum on it, and reply back the client with the checksum.
//
// The server prints out its pid and chid so that the client can be made aware
// of them.
//
// Using the comments below, put code in to complete the program.  Look up 
// function arguments in the course book or the QNX documentation.
////////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/neutrino.h>
#include <process.h>

#include "msg_def.h"  //layout of msg's should always defined by a struct, here's its definition

int
calculate_checksum(char *text);

int main(void)
{
    int chid;
    int pid;
    int rcvid;
    cksum_msg_t msg;
    int status;
    int checksum;

    //PUT CODE HERE to create a channel, store channel id in the chid variable
    chid = ChannelCreate(0);
    if (-1 == chid)
    { //was there an error creating the channel?
        perror("ChannelCreate()"); //look up the errno code and print
        exit(EXIT_FAILURE);
    }

    pid = getpid(); //get our own pid
    printf("Server's pid: %d, chid: %d\n", pid, chid); //print our pid/chid so
    //client can be told where to connect
    while (1)
    {
        //PUT CODE HERE to receive msg from client
        rcvid = MsgReceive(chid, &msg,sizeof(msg),NULL);
        if (-1 == rcvid)
        { //was there an error receiving msg?
            perror("MsgReceive"); //look up errno code and print
            exit(EXIT_FAILURE); //give up
        }

        //PUT CODE HERE to calculate the check sum by calling calculate_checksum()

        checksum = calculate_checksum(msg.string_to_cksum);
        //PUT CODE HERE TO reply to client with checksum, store the return status in status
        status = MsgReply(rcvid,EOK,&checksum,sizeof(checksum));

        if (-1 == status)
        {
            perror("MsgReply");
            exit(EXIT_FAILURE);
        }
    }
    return 0;
}

int calculate_checksum(char *text)
{
    char *c;
    int cksum = 0;

    for (c = text; *c != NULL; c++)
        cksum += *c;
    return cksum;
}
Romanof123 commented 4 years ago

message test client

////////////////////////////////////////////////////////////////////////////////
// client.c
//
// A QNX msg passing client.  It's purpose is to send a string of text to a
// server.  The server calculates a checksum and replies back with it.  The client
// expects the reply to come back as an int
//
// This program program must be started with commandline args.  
// See  if(argc != 4) below
//
// To complete the exercise, put in the code, as explained in the comments below
// Look up function arguments in the course book or the QNX documentation.
////////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/neutrino.h>
#include <sys/netmgr.h>     // #define for ND_LOCAL_NODE is in here
#include "msg_def.h"

int main(int argc, char* argv[])
{
    int coid; //Connection ID to server
    cksum_msg_t msg;
    int incoming_checksum; //space for server's reply
    int status; //status return value used for ConnectAttach and MsgSend
    int server_pid; //server's process ID
    int server_chid; //server's channel ID

    if (4 != argc)
    {
        printf("ERROR: This program must be started with commandline arguments, for example:\n\n");
        printf("   client 482834 1 abcdefghi    \n\n");
        printf(" 1st arg(482834): server's pid\n");
        printf(" 2nd arg(1): server's chid\n");
        printf(" 3rd arg(abcdefghi): string to send to server\n"); //to make it 
        //easy, let's not bother handling spaces
        exit(EXIT_FAILURE);
    }

    server_pid = atoi(argv[1]);
    server_chid = atoi(argv[2]);

    printf("attempting to establish connection with server pid: %d, chid %d\n", server_pid,
            server_chid);

    //PUT CODE HERE to establish a connection to the server's channel, store the
    coid = ConnectAttach(ND_LOCAL_NODE,server_pid,server_chid,_NTO_SIDE_CHANNEL,0);
    //connection id in the variable 'coid'

    if (-1 == coid)
    { //was there an error attaching to server?
        perror("ConnectAttach"); //look up error code and print
        exit(EXIT_FAILURE);
    }

    msg.msg_type = CKSUM_MSG_TYPE;
    strcpy(msg.string_to_cksum, argv[3]);
    printf("Sending string: %s\n", msg.string_to_cksum);

    //PUT CODE HERE to send message to server and get the reply
    status = MsgSend(coid, &msg,sizeof(msg),&incoming_checksum,sizeof(incoming_checksum));
    if (-1 == status)
    { //was there an error sending to server?
        perror("MsgSend");
        exit(EXIT_FAILURE);
    }

    printf("received checksum=%d from server\n", incoming_checksum);
    printf("MsgSend return status: %d\n", status);

    return EXIT_SUCCESS;
}
Romanof123 commented 4 years ago

massage 주의할것은?


- 저 type말하는거임 511 까지 커널이 쓰고있음.
msg_def.h가 있음