Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 12:02

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



C++ Pipe

Discussion on C++ Pipe within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2011
Posts: 35
Received Thanks: 123
C++ Pipe

Hallo liebe Community

Kann mir jemand erklären wie ich in c++ eine pipe baue die mit meinem c# programm kommunizieren kann? hab im internet kein gutes tutorial dazu gefunden wenn jemand eins hat pls verlinken.


schon mal Danke im vorraus ^^
insert-name-here is offline  
Old 12/26/2011, 01:37   #2
 
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
Sollte reichen

Den C# Teil kriegst du ja denke ich selber hin. NamedPipedServerStream/NamedPipedClientStream.
MoepMeep is offline  
Old 12/26/2011, 13:29   #3
 
elite*gold: 0
Join Date: Dec 2011
Posts: 35
Received Thanks: 123
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 ?
insert-name-here is offline  
Old 12/26/2011, 13:55   #4
 
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
Man kann ja wohl erwarten, dass du die entsprechenden msdn artikel liest, oder?

Quote:
Return value

If the function succeeds, the return value is a handle to the server end of a named pipe instance.

If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
MoepMeep is offline  
Old 12/26/2011, 13:59   #5
 
elite*gold: 0
Join Date: Dec 2011
Posts: 35
Received Thanks: 123
Leute ich hab jetzt diesen code hier
Code:
int _tmain(int argc, _TCHAR* argv[])
{
  LPCTSTR _PIPE_NAME = L"\\\\.\\pipe\\ShaiyaPipe";
  HANDLE hPipe = CreateFile(_PIPE_NAME, GENERIC_WRITE,0, NULL, OPEN_EXISTING,0, NULL);

  if(INVALID_HANDLE_VALUE == hPipe) {
    cout << "Konnte Pipe nicht ffnen" << endl;
    return 0;
  }

  DWORD nofRead;
  
  char bufIn [1000];
  while (1) {
    ReadFile(hPipe,
    bufIn, sizeof(bufIn), &nofRead, NULL);

    bufIn[nofRead]=0;
    cout << ">" << bufIn << endl;
	Sleep(1000);
  }
  return 0;
}
für die Pipe
aber in der Konsole steht nur müll und nicht das was ich mit dem server gesendet hab von C# zu C# klapts wunderbar kann mir jemand sagen wo der fehler im code ist oder mir grade eine c++ pipe bauen die einen einfachen wert empfangen kann
Danke schon mal im vorraus
MFG
Insert-name-here

Kann oder will mir keiner dabei helfen ?
insert-name-here is offline  
Old 12/31/2011, 17:55   #6
 
elite*gold: 20
Join Date: Sep 2006
Posts: 1,100
Received Thanks: 184
Es ist vermutlich ein Problem mit dem Stringencoding, wenn du UTF-8 Strings per C# verschickst und diese dann als ANSI ließt kommt einfach nur Kauderwelsch dabei heraus.

Du musst also den String in C++ richtig verarbeiten, benütze also besser einen wchar_t buffer und wcout.
Bot_interesierter is offline  
Reply


Similar Threads Similar Threads
Pipe Wrench
08/18/2010 - WarRock - 7 Replies
Hallo liebe Community, ich wollte einmal fragen was genau das Pipe Wrench bringt. Soweit ich weiß repariert es Fahrzeige statt mit den üblichen 12 % mit 24 % und zudem kann man damit Bomben entschärfen aber nun zum wichtigsten Teil meiner Frage: Um wieviel Schneller kann man damit die Bomben entschärfen? Kann das mal bitte jemand stoppen, falls es keiner weiß ich überlege mir nämlich dieses Teil zu kaufen da ich eh zur zeit viel Engineer zocke ! Achja und die SuFu hab ich benutzt aber...
message pipe block shit plase help me!!!
04/27/2010 - CO2 Private Server - 4 Replies
Hello All guys any 1 know how to fix this message pipe block problem?? plase help me http://img51.imageshack.us/img51/5751/sssssl.png images :confused::confused::confused:



All times are GMT +1. The time now is 12:02.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.