当前位置:网站首页>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;
}
边栏推荐
- 【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
- numpy 创建空数组 data = np.empty(shape=[1, 64,64,3])
- Google Earth Engine(GEE)——将字符串的转化为数字并且应用于时间搜索( ee.Date.fromYMD)
- Je suis à Foshan, où puis - je ouvrir un compte? L'ouverture d'un compte par téléphone mobile est - elle sécurisée?
- get请求与post提交区别的简易理解
- Introduction to the renewal of substrate source code: the pallet alliance is incorporated into the main line,
- Numpy creates an empty array data = np empty(shape=[1, 64,64,3])
- mysql拒绝访问、管理员身份打开的
- Deep understanding Net (2) kernel mode 4 Summary of kernel pattern constructs
- Read all the knowledge points about enterprise im in one article
猜你喜欢

"As a service", the inevitable choice of enterprise digital transformation

IM即时通讯应用开发中无法解决的“顽疾”

这个编辑器即将开源!

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

Read all the knowledge points about enterprise im in one article
![[kali] Kali system, software update (with image source)](/img/ac/43a3f81d50ab6866271b500b142252.png)
[kali] Kali system, software update (with image source)

Loss function: Diou loss handwriting implementation

深入理解.Net中的线程同步之构造模式(二)内核模式2.内核模式构造物Semaphone

Getting started with shell Basics

Unity animator parameter
随机推荐
数据库表为什么写不进数据了
Optimization of unit test efficiency: why test programs? What are the benefits of testing?
服务线上治理
DNS 解析之家庭网络接入 Public DNS 实战
一文讲清楚什么是类型化数组、ArrayBuffer、TypedArray、DataView等概念
可观测,才可靠:云上自动化运维CloudOps系列沙龙 第一弹
exlipse同时操作多行。比如同时在多行同列输入相同的文字
Getting started with shell Basics
重磅:国产IDE发布,由阿里研发,完全开源!
逆向调试入门-PE中的VA与RVA换算04/07
Observable, reliable: the first shot of cloudops series Salon of cloud automation operation and maintenance
Dart 扩展特性
“即服务”,企业数字化转型的必然选择
数字时代,XDR(扩展检测与响应)的无限可能
Unity Animator 参数
This editor will open source soon!
Intelligent operation and maintenance: visual management system based on BIM Technology
腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
深入理解.Net中的线程同步之构造模式(二)内核模式3.内核模式构造物Mutex
[the path of system analyst] Chapter 5 Software Engineering (Agile Development)