Ich hab im Internet 2 Pipe's gefunden eine C# und eine C++ aber das mit dem verbinden klapt nicht so ganz richtig :-/
Die C# Pipe
Code:
using System;
using System.IO;
using System.IO.Pipes;
namespace PipeServer
{
internal class Program
{
private static void Main()
{
while (1 == 1)
{
using (var pipeServerStream = new NamedPipeServerStream("ShaiyaPipe"))
{
Console.WriteLine("Waiting for connection.");
pipeServerStream.WaitForConnection();
Console.WriteLine("Connected to client.");
using (var streamReader = new StreamReader(pipeServerStream))
{
var data = streamReader.ReadLine();
if (data != null)
Console.WriteLine("Received: " + data);
}
}
}
}
}
}
so und jetzt die C++ Pipe
Code:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <tchar.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hPipe = ::CreateNamedPipeA((LPSTR)"\\\\.\\pipe\\ShaiyaPipe",
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES, 4096, 4096,
NMPWAIT_USE_DEFAULT_WAIT, NULL);
if(hPipe== INVALID_HANDLE_VALUE)
printf("fail\n");
else
printf("work");
ConnectNamedPipe(hPipe, NULL);
for(;;)
{
if(ConnectNamedPipe(hPipe, NULL)==0)
{
printf("ConnectNamedPipe(hPipe, NULL)==0\n");
if(GetLastError()==ERROR_NO_DATA)
{
printf("previous closed,ERROR_NO_DATA\n");
DisconnectNamedPipe(hPipe);
ConnectNamedPipe(hPipe, NULL);
}
}
else
printf("Client Connected!\n");
Sleep(2000);
};
Sleep(10000);
}
Da stimmt ja schon was mit der hPipe== INVALID_HANDLE_VALUE nicht aber was ?