资源简介
使用消息队列与共享内存完成一个简单的终端聊天程序

代码片段和文件信息
#include “public.h“
void *login_ptr = NULL;
void signal_login(int signo)
{
int i = 0;
printf(“new user login\n“);
char login_head[100] = {0};
memcpy(login_headlogin_ptr100);
printf(“current online users:\n“);
for (i = 0;i < 100;i++)
{
//表示被使用,有数据
if (login_head[i] == 1)
{
int pos = 100 + sizeof(int) * i;
int pid = 0;
memcpy(&pid(char*)login_ptr + possizeof(int));
printf(“ %d “pid);
}
}
printf(“\n“);
}
int main()
{
signal(SIGUSR1signal_login);
//登录消息
//创建一个登录消息队列
int msg_login_id = msgget((key_t)0001IPC_CREAT | 0766);
if (msg_login_id < 0)
{
printf(“create msg error!“);
return 0;
}
//打开在线用户共享内存
int shmid = shmget((key_t)123400);
if (shmid < 0)
{
printf(“open shm error!“);
}
//映射逻辑地址
login_ptr = shmat(shmidNULL0);
LOGIN_T login;
memset(&login0sizeof(LOGIN_T));
login.type = 1;//表示登录
login.pid = getpid();
//发送登录数据
int ret = msgsnd(msg_login_id(void*)&loginsizeof(LOGIN_T)-sizeof(long)0);
if (ret < 0)
{
printf(“send login msg error!“);
return 0;
}
while (1)
{
sleep(1);
}
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-08-05 00:10 IPC_chat\
目录 0 2016-08-05 10:29 IPC_chat\IPC_chat\
文件 1567744 2016-08-05 10:29 IPC_chat\IPC_chat.ncb
文件 890 2016-08-05 00:10 IPC_chat\IPC_chat.sln
文件 11264 2016-08-05 10:29 IPC_chat\IPC_chat.suo
文件 1202 2016-08-05 10:29 IPC_chat\IPC_chat\client.cpp
文件 4042 2016-08-05 08:56 IPC_chat\IPC_chat\IPC_chat.vcproj
文件 1415 2016-08-05 10:29 IPC_chat\IPC_chat\IPC_chat.vcproj.lenovo-PC.lenovo.user
文件 385 2016-08-05 08:58 IPC_chat\IPC_chat\public.h
文件 29016 2016-08-05 10:25 IPC_chat\IPC_chat\server
文件 1520 2016-08-05 10:29 IPC_chat\IPC_chat\server.cpp
相关资源
- 《ONVIF协议网络摄像机IPC客户端程序开
- onvif协议网络摄像机(IPC)客户端程序
- 8P_15225714_Unicom_cn_iPhone.ipcc
- 130万IPC固件
- IPCamAdapter_x64
- TI公司元件封装库
- M.2 PCIE MINIPICE MINISODIMM
- 国外PCB封装库贴片元件封装尺寸 IPC
- ClipCache Pro 3.5.3(剪切板缓存 专业版)
- 剪贴板增强工具_ClipCache Pro 3.6.1安装
- IPC SDK_V6.24.01.rar
- NYC Zip Code ShapeFile 纽约的zipcode shapfi
- 天视通SDK使用
- IPCamAdapter.msi程序
- ZipCode201808.rar
- IPcamera38*38模块
- IPCJ-STD-001ECHINESE-2010(焊接的电气和电
- 福大fzu OJ题目
- IPCJ-STD-002CCHINESE-2008.rar
- 中兴PCB元件封装库命名规范-IPC7351
- 各类板卡的物理尺寸规范
- NT96660数据手册
- ipcamadapter_x64 ip camera adapter 64 bit
- 西门子SIMATIC IPC3000 SMART产品简介.pdf
- 许可文件.zipCOMSOL Multiphysics® 5.4 版本
- HiMPP IPC V2.0 媒体处理软件开发参考
- ipcam的vs工程
- EasyIPCameraSimulator
- IPCToolSetup.zip
- Onvif device manager v2.2.250
评论
共有 条评论