如题,是实现网络通信,我的想法是server端接收client端发来的数据后,以接收到的数据作为createprocess子进程要执行的命令,然后将结果传回到另一台主机的client端,自己试了一下并没有成功,是不能吗?

解决方案 »

  1.   

    client是能写但不能读的,楼主是client不能读是不
      

  2.   

    客户端
    #include <windows.h>
    #include <iostream> 
    using namespace std;
    const TCHAR szPipeName[] = "\\\\.\\pipe\\fuckyou";int main()
    {   
        HANDLE hPipe = CreateFile(szPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);   
        if (hPipe == INVALID_HANDLE_VALUE)   
        {   
            printf("CreateFile return [%d]!\n", GetLastError());   
            return -1;   
        }
        DWORD dwRead, dwWrite;   
        char szBuf[1024];
    memset(szBuf, 0, sizeof(szBuf));
        sprintf(szBuf, "time");   
        WriteFile(hPipe, szBuf, strlen(szBuf), &dwWrite, 0);   
        printf("Send %s\n", szBuf);   
        memset(szBuf, 0, sizeof(szBuf));   
        ReadFile(hPipe, szBuf, sizeof(szBuf), &dwRead, 0);   
        printf("Recv \n%s\n", szBuf); 
    CloseHandle(hPipe);