mailslot通信行吗?请。。。。(50分)

  • 主题发起人 主题发起人 hnlfh
  • 开始时间 开始时间
H

hnlfh

Unregistered / Unconfirmed
GUEST, unregistred user!
现在公司想通过mailslot做应用程序通信代理,公司这样做行吗?
 
“应用程序通信代理”是什么意思?
我觉得mailslot的缺点是:
1.只能用在同一个局域网内。
2.通信用的是计算机名或工作组名而非IP地址。
3.不支持广播。
 
Support broadcast.
Just use loop
 
to yyanghhong:
How to use loop to support broadcast,can you say more about it?
 
you can get all of the computer name in the local networking, then use loop to
send message one by one,
 
That's not broadcast,but unicast one by one.
It's not a good idea.Can you find a good way to get all the computer names
quickly?(You can get all the computer name ,but it takes a lot of time.)
Second,the hosts on a LAN can change dynamicly.
 
用Socket或者是COM吧
 
First of all, You might use the function below to get a list of computer name,
then you can store this list to a file or database, and develop a service to maintain
it at intervals, other computers will access this file or database to get this list.

BOOL WINAPI EnumerateFunc(HWND hwnd,
HDC hdc,
LPNETRESOURCE lpnr)
{
DWORD dwResult, dwResultEnum;
HANDLE hEnum;
DWORD cbBuffer = 16384; // 16K is a good size
DWORD cEntries = 0xFFFFFFFF; // enumerate all possible entries
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
DWORD i;

dwResult = WNetOpenEnum(RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,

0, // enumerate all resources
lpnr, // NULL first time this function is called
&hEnum); // handle to resource

if (dwResult != NO_ERROR) {

// An application-defined error handler is demonstrated in the
// section titled "Retrieving Network Errors."

NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetOpenEnum");
return FALSE;
}

do {

// Allocate memory for NETRESOURCE structures.


lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);

dwResultEnum = WNetEnumResource(hEnum, // resource handle
&cEntries, // defined locally as 0xFFFFFFFF
lpnrLocal, // LPNETRESOURCE
&cbBuffer); // buffer size

if (dwResultEnum == NO_ERROR) {
for(i = 0; i < cEntries; i++)
{
// Following is an application-defined function for

// displaying contents of NETRESOURCE structures.

DisplayStruct(hdc, &amp;lpnrLocal);

//
// If this NETRESOURCE is a container, call the function
// recursively.

if(RESOURCEUSAGE_CONTAINER ==
(lpnrLocal.dwUsage &amp; RESOURCEUSAGE_CONTAINER))
if(!EnumerateFunc(hwnd, hdc, &amp;lpnrLocal))
TextOut(hdc, 10, 10,

"EnumerateFunc returned FALSE.", 29);

}
}

else if (dwResultEnum != ERROR_NO_MORE_ITEMS) {
NetErrorHandler(hwnd, dwResultEnum, (LPSTR)"WNetEnumResource");
break;
}
}
while(dwResultEnum != ERROR_NO_MORE_ITEMS);

GlobalFree((HGLOBAL) lpnrLocal);

dwResult = WNetCloseEnum(hEnum);

if(dwResult != NO_ERROR) {
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCloseEnum");

return FALSE;
}

return TRUE;
}
 
To yyanghhong:
Of cause,this function works,but some times this function also takes a lot of
time.(I know this function well,and I also use this function to make a program
to seach the files on the LAN,http://delphi.mychangshu.com/dispdoc.asp?id=451),
More import,the hosts on a LAN can change dynamicly.In order to solve this problem
you have to search the groups frequently,so it's not a good idea.
 
后退
顶部