当前位置:网站首页>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;
}
边栏推荐
- Defi "where does the money come from"? A problem that most people don't understand
- Numpy creates an empty array data = np empty(shape=[1, 64,64,3])
- Waving flags and shouting for basic language
- 香港回归20余年,图扑数字孪生港珠澳大桥,超震撼
- 数据库表为什么写不进数据了
- PG Basics - logical structure management (table inheritance, partition table)
- [kubernetes series] k8s set mysql8 case insensitive
- 为基础性语言摇旗呐喊
- 想請教一下,我在佛山,到哪裏開戶比較好?手機開戶是安全麼?
- 正则系列之断言Assertions
猜你喜欢

Jetpack Compose 实现完美屏幕适配

Unity Animator 参数

mysql拒绝访问、管理员身份打开的

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

Pytorch查看模型参数量和计算量

Configuration of headquarters dual computer hot standby and branch infrastructure for firewall Foundation

Introduction to two types of rxjs observable operators

SQL编程问题,测试用例不通过
![[kali] Kali system, software update (with image source)](/img/ac/43a3f81d50ab6866271b500b142252.png)
[kali] Kali system, software update (with image source)
![[scientific research data processing] [basic] category variable frequency analysis chart, numerical variable distribution chart and normality test (including lognormal)](/img/70/8bf226964118efb324ca4d339df654.png)
[scientific research data processing] [basic] category variable frequency analysis chart, numerical variable distribution chart and normality test (including lognormal)
随机推荐
用Unity实现Flat Shading
Basic syntax of unity script (1) - common operations of game objects
Service online governance
目录相关命令
Knowledge dissemination cannot replace professional learning!
60 divine vs Code plug-ins!!
Observable, seulement fiable: première bombe de salon de la série cloudops d'exploitation et d'entretien automatisés dans le nuage
【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
Apache Doris Compaction优化百科全书
DeFi“钱从哪来”?一个大多数人都没搞清楚的问题
In the digital age, XDR (extended detection and response) has unlimited possibilities
Intelligent operation and maintenance: visual management system based on BIM Technology
Loss function: Diou loss handwriting implementation
MySQL access denied, opened as Administrator
Waving flags and shouting for basic language
Google Earth engine (GEE) - ghsl: global human settlements layer, built grid 1975-1990-2000-2015 (p2016) data set
Multi terminal collaboration of Huawei accounts to create a better internet life
SQL考勤统计月报表
深入理解.Net中的线程同步之构造模式(二)内核模式2.内核模式构造物Semaphone
香港回归20余年,图扑数字孪生港珠澳大桥,超震撼