当前位置:网站首页>Impersonate server and client using message queuing
Impersonate server and client using message queuing
2022-06-30 14:06:00 【Fat Xiao Deng】
Use message queuing to simulate server and client
client 1 Send a message to the server , The sent message carries the identity of the message receiver
client 2 Send a message to the server , The sent message carries the identity of the message receiver
Server side : receive messages , According to the message receiver ID in the message , Forward to the corresponding message receiver .
// Server side
server.c
#include "myhead.h"
typedef struct msgbuf
{
long mtype; // Identification of the message
char mtext[100]; // The body of the message
}MSG;
int main(int argc, char const *argv[])
{
if (argc != 2)
{
printf("%s Message ID \n", argv[0]);
return -1;
}
int msgid, key;
key = ftok("./", 1);
if (key == -1)
{
perror("ftok() failed!");
return -1;
}
msgid = msgget(key, IPC_CREAT | 0666);
if (msgid == -1)
{
perror("msgget() failed!");
return -1;
}
MSG msg;
int mtype=atoi(argv[1]);
while(1)
{
//bzero(msg.mtext, sizeof(msg.mtext));
printf(" Enter the message to send Ser->Cli:");
scanf("%s",msg.mtext);
int ret = msgsnd(msgid, &msg, strlen(msg.mtext)+1, 0);
if (ret == -1)
{
perror("msgsnd() failed!");
return -1;
}
msgrcv(msgid,&msg,sizeof(msg), mtype,0);// Receive ID is mtype The news of
printf(" Messages received Cli->Ser: %s\n",msg.mtext);
}
msgctl(msgid,IPC_RMID,NULL);
return 0;
}
// The end of the service
client.c
#include "myhead.h"
typedef struct msgbuf
{
long mtype; // Identification of the message
char mtext[100]; // The body of the message
}MSG;
int main(int argc, char const *argv[])
{
if (argc != 2)
{
printf("%s Message ID \n", argv[0]);
return -1;
}
int msgid, key;
key = ftok("./", 1);
if (key == -1)
{
perror("ftok() failed!");
return -1;
}
msgid = msgget(key, IPC_CREAT | 0666);
if (msgid == -1)
{
perror("msgget() failed!");
return -1;
}
MSG msg;
int mtype=atoi(argv[1]);
while(1)
{
//bzero(msg.mtext, sizeof(msg.mtext));
msgrcv(msgid, &msg, sizeof(msg), mtype, 0);// Receive ID is mtype The news of
printf(" Messages received Ser->Cli:%s\n",msg.mtext);
printf(" Enter the message to send Cli->Ser: ");
scanf("%s",msg.mtext);
int ret = msgsnd(msgid, &msg, strlen(msg.mtext)+1, 0);
if (ret == -1)
{
perror("msgsnd() failed!");
return -1;
}
printf(" Message sent successfully \n");
}
return 0;
}
边栏推荐
- Lifting scanning tool
- Google Earth engine (GEE) - ghsl: global human settlements layer, built grid 1975-1990-2000-2015 (p2016) data set
- 【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
- 编程实战赛来啦!B站周边、高级会员等好礼送你啦!
- Data Lake (11): Iceberg table data organization and query
- 服务线上治理
- STM32 porting the fish component of RT thread Standard Edition
- 用Unity实现Flat Shading
- 提权扫描工具
- 科普达人丨漫画图解什么是eRDMA?
猜你喜欢

防火墙基础之总部双机热备与分支基础配置
![【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)](/img/5a/eaa845f4332f0b8ee8b6409d6a79e8.png)
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)

60 divine vs Code plug-ins!!

SQL attendance statistics monthly report

WTM major updates, multi tenancy and single sign on

QQ was stolen? The reason is

Tencent two sides: @bean and @component are used on the same class. What happens?

Introduction to two types of rxjs observable operators
![[scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)](/img/5a/eaa845f4332f0b8ee8b6409d6a79e8.png)
[scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)

Shell programming overview
随机推荐
Inexplicable error occurred in unity's frequent switching branch result model
华为帐号多端协同,打造美好互联生活
MySQL access denied, opened as Administrator
Flat shading with unity
SQL attendance statistics monthly report
In the digital age, XDR (extended detection and response) has unlimited possibilities
Google Earth engine (GEE) -- converts string to number and applies it to time search (ee.date.fromymd)
With the development of industrial Internet, the landing and application of the Internet has become wider
Jetpack Compose 实现完美屏幕适配
[the path of system analyst] Chapter V software engineering (software process improvement)
幸运哈希竞猜系统开发(源码部署)趣投哈希游戏玩法开发(案例需求)
Comprehensively analyze the basic features and summary of free and paid SSH tools
This editor will open source soon!
“即服务”,企业数字化转型的必然选择
[Title brushing] avoid flooding
Golang template (text/template)
What is erdma as illustrated by Coptic cartoon?
[kubernetes series] k8s set mysql8 case insensitive
Lifting scanning tool
Lucky hash quiz system development (source code deployment) fun investment hash game play development (case requirements)