vc中邮槽通信的问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 12:30:21
我自己照孙鑫老师的书编写了一个邮槽服务器端和客户端程序,但是点击客户端的发送在服务器端收不到;我将客户端的CreateFile("\\\\192.168.173.123\\mailslot\\MyMailslot",GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);函数中的服务器名字采用了IP地址的形式,这个时候服务器收不到信息。
但是如果将服务器名字改为“.”或计算机的名字或*时服务器却可以受到客户端发送的信息,难道是createfile函数检索服务器名字时不能用IP地址么,请各位大虾帮忙看看!!!!

服务器程序如下:
HANDLE hMailslot;//创建邮槽
hMailslot=CreateMailslot("\\\\.\\mailslot\\MyMailslot",0,4000,NULL);
if (INVALID_HANDLE_VALUE==hMailslot) {
MessageBox("创建油槽出错");
return;
}
char buf[100];
DWORD dwRecv;
if (!ReadFile(hMailslot,buf,100,&dwRecv,NULL)) {
MessageBox("从油槽中读取数据出错");
CloseHandle(hMailslot);
return;
}
MessageBox(buf);
CloseHandle(hMailslot);

客户端程序:
HANDLE hMailslot;
//打开邮槽
hMailslot=CreateFile("\\\\192.168.173.233\

通过API:
HANDLE WINAPI CreateMailslot(
__in LPCTSTR lpName,
__in DWORD nMaxMessageSize,
__in DWORD lReadTimeout,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes
);

lpName赋值为 \\\\192.168.173.123\\mailslot\\MyMailslot