Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
HR_Socket_Msg_Demo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马伊齐
HR_Socket_Msg_Demo
Commits
4d80c5d2
Commit
4d80c5d2
authored
Dec 20, 2023
by
马伊齐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
msg发送接收Demo
parent
b0db938c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
2 deletions
+53
-2
MsgClient.c
msg_send_recv/MsgClient.c
+24
-1
MsgServer.c
msg_send_recv/MsgServer.c
+29
-1
No files found.
msg_send_recv/MsgClient.c
View file @
4d80c5d2
#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
msg_send_recv/MsgServer.c
View file @
4d80c5d2
#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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment