您现在的位置是: 软件 > 开发者网络 > 程序方舟 > 系统编程 > 正文


-Win xp中的多种网络
-试验试验试验试验
-用Freehand实现位图矢量化
-网络电话面面观

Win32程序设计之网络通信
2001-05-31· ·QQ新人类编译··yesky

上一页  1 2 3 4 5 6 7  


  列表5

  一个命名管道客户,可连接到列表4中的程序,并且发送信息给它

//***************************************************************
// From the book "Win32 System Services: The Heart of Windows NT"
// by Marshall Brain
// Published by Prentice Hall
file://
// Copyright 1994, by Prentice Hall.
file://
// This code implements a simple named pipe sender.
file://***************************************************************

// ssnpsend.cpp

// Usage: ssnpsend

#include
#include

int main()
{
char *toSendtxt="Test String";
HANDLE ssnpPipe;
DWORD NumBytesWritten;
char machineName[80];
char pipeName[80];

cout << "Enter name of server machine: ";
cin >> machineName;
wsprintf(pipeName, "\\\\%s\\pipe\\ssnp",
machineName);

/* Create the named pipe file handle for sending
messages */
ssnpPipe=CreateFile(pipeName,
GENERIC_WRITE, FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES) NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
(HANDLE) NULL);

/* Check and see if the named pipe file was
opened, if not terminate program */
if (ssnpPipe == INVALID_HANDLE_VALUE)
{
cerr << "ERROR: Unable to create a named pipe "
<< endl;
cerr << GetLastError() << endl;
return (1);
}

/* Repeatedly send message until program is
terminated */
while(1)
{
cout << "Sending..." << endl;
/* Write message to the pipe */
if (!WriteFile(ssnpPipe,
toSendtxt, (DWORD) strlen(toSendtxt)+1,
&NumBytesWritten, (LPOVERLAPPED) NULL))
{
/* If error occurs when writing to named
pipe, terminate program */
cerr << "ERROR: Unable to write to named pipe "
<< GetLastError() << endl;
CloseHandle(ssnpPipe);
return (1);
}

/* Wait before sending the message again */
Sleep(4800);
} /* while*/
}




上一页  1 2 3 4 5 6 7  

【责任编辑:方舟】
【发表评论】【关闭窗口】
■ 相关内容
 C++BUILDER动态建立菜单及菜单事件
 Win32程序设计之系统安全
 Win32程序设计之服务
 WIN32程序设计之线程
感谢 访问天极网,如果您觉得该文章涉及版权问题,请看这里!