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
9a50cba3
Commit
9a50cba3
authored
Dec 11, 2023
by
马伊齐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初版本地消息发送接收Demo
parent
d9505246
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
0 deletions
+83
-0
MsgLocalClient.c
msg_local_send_recv/MsgLocalClient.c
+38
-0
MsgLocalServer.c
msg_local_send_recv/MsgLocalServer.c
+45
-0
No files found.
msg_local_send_recv/MsgLocalClient.c
0 → 100644
View file @
9a50cba3
#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
(
int
argc
,
char
*
argv
[])
{
char
buffer
[
BUFFER_SIZE
];
if
(
init_msg_queue
()
==
-
1
)
{
exit
(
EXIT_FAILURE
);
}
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
stdin
)
!=
NULL
)
{
if
(
msg_local_send
(
MSG_CAN_HEARTBEAT
,
0
,
(
void
*
)
buffer
,
strlen
(
buffer
))
==
-
1
)
{
destroy_msg_queue
();
exit
(
EXIT_FAILURE
);
}
// 清空buffer
memset
(
buffer
,
0
,
sizeof
(
buffer
));
}
// 清理消息队列
if
(
destroy_msg_queue
()
==
-
1
)
{
exit
(
EXIT_FAILURE
);
}
return
0
;
}
\ No newline at end of file
msg_local_send_recv/MsgLocalServer.c
0 → 100644
View file @
9a50cba3
#include <sys/ipc.h>
#include <stdint.h>
#include <stdio.h>
#include <error.h>
#include <stdlib.h>
#include <sys/msg.h>
#include <string.h>
#include "../lib/sock_msg.h"
int
main
(
int
argc
,
char
*
argv
[])
{
msg_data_t
msg
;
// 初始化消息队列
if
(
init_msg_queue
()
==
-
1
)
{
exit
(
EXIT_FAILURE
);
}
while
(
1
)
{
if
(
msg_local_recv
(
&
msg
)
>
0
)
{
printf
(
"Received code: %d
\n
"
,
msg
.
code
);
printf
(
"Received type: %d
\n
"
,
msg
.
type
);
printf
(
"Received len: %d
\n
"
,
msg
.
len
);
printf
(
"Received pad: %s
\n
"
,
(
char
*
)(
msg
.
pad
));
// 清空pad
memset
(
msg
.
pad
,
0
,
msg
.
len
);
}
else
{
destroy_msg_queue
();
exit
(
EXIT_FAILURE
);
}
}
// 清理消息队列
if
(
destroy_msg_queue
()
==
-
1
)
{
exit
(
EXIT_FAILURE
);
}
return
0
;
}
\ No newline at end of file
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