質問

ここで見つけるクライアントとサーバの例を使用する: http://www.winsocketdotnetworkprogramming.com/ winsock2programming / winsock2advancedmailslot14.html に、その後、VS2008でそれらをコンパイルサーバを実行し、「クライアントMyslot」私は「WriteFailがエラー53で失敗しました」得続けます誰もが任意のアイデアがありますか?他のメールスロットの例へのリンクも歓迎され、感謝しています。

サーバー:

    // Server sample
#include <windows.h>
#include <stdio.h>

void main(void)
{

    HANDLE Mailslot;
    char buffer[256];
    DWORD NumberOfBytesRead;

    // Create the mailslot

    if ((Mailslot = CreateMailslot("\\\\.\\Mailslot\\Myslot", 0, MAILSLOT_WAIT_FOREVER, NULL)) == INVALID_HANDLE_VALUE)
    {
        printf("Failed to create a mailslot %d\n", GetLastError());
        return;
    } 

    // Read data from the mailslot forever!

    while(ReadFile(Mailslot, buffer, 256, &NumberOfBytesRead, NULL) != 0)
    {
        printf("%.*s\n", NumberOfBytesRead, buffer);
    }
}

クライアント:

// Client sample

#include <windows.h>
#include <stdio.h>

void main(int argc, char *argv[])
{
    HANDLE Mailslot;
    DWORD BytesWritten;
    CHAR ServerName[256];

    // Accept a command line argument for the server to send a message to

    if (argc < 2)
    {
        printf("Usage: client <server name>\n");
        return;
    }

    sprintf(ServerName, "\\\\%s\\Mailslot\\Myslot", argv[1]);

    if ((Mailslot = CreateFile(ServerName, GENERIC_WRITE,

        FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)
    {
        printf("CreateFile failed with error %d\n", GetLastError());
        return;
    }

    if (WriteFile(Mailslot, "This is a test", 14, &BytesWritten, NULL) == 0)
    {
        printf("WriteFile failed with error %d\n", GetLastError());
        return;
    }

    printf("Wrote %d bytes\n", BytesWritten);
    CloseHandle(Mailslot);
}
役に立ちましたか?

解決

エラー53 ERROR_BAD_NETPATHで、「ネットワークパスが見つかりませんでした」。明らかに、あなたはメールスロットのために間違ったサーバー名を使用しています。サーバーがクライアントと同じマシン上で実行されている場合\\.\mailslot\blahを使用してください。そして、文字列内のバックスラッシュをエスケープすることを忘れないでください:。"\\\\.\\mailslot\\blah"

他のヒント

私は、2つのファイルに掲載コードを正確にコピーしたVS2008でそれらをコンパイルし、彼らが完全に走りました。クライアントプログラムがクライアント。としてコンパイルされている場合は、次のコマンドを入力します:

client .

または

client <computername>

ここで、コンピュータ名は、ドメインなしでPCの名前です。あなたは名前を取得するために GetComputerNameののAPIを呼び出すことができます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top