Commit 4d80c5d2 authored by 马伊齐's avatar 马伊齐

msg发送接收Demo

parent b0db938c
#include<stdio.h>
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include "../lib/sock_msg.h"
int main()
{
char buffer[BUFFER_SIZE];
while(fgets(buffer, BUFFER_SIZE, stdin) != NULL)
{
buffer[strlen(buffer) - 1] = '\0';
if (msg_send(MSG_CHAN_APP, MSG_KEY_PRESS, 123, (void *)buffer, strlen(buffer)) < 0)
{
fprintf(stderr, "Failed to send message\n");
}
}
return 0;
}
\ No newline at end of file
#include<stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/msg.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>
#include "../lib/sock_msg.h"
int main(int argc, char *argv[])
{
msg_data_t received_msg;
printf("MsgServer started\n");
while (msg_recv(MSG_CHAN_APP, &received_msg) > 0)
{
printf("Received message type: %d, code: %d, len: %d, content: %s\n", received_msg.type, received_msg.code, received_msg.len, (char *)received_msg.pad);
}
perror("msg_recv: ");
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment