C#与C ++ dll的TCP连接 [英] c# TCP connection with a C++ dll

查看:106
本文介绍了C#与C ++ dll的TCP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何在C#中开发与该现有C ++库进行通信(发送和接收)的程序??

该库已经开发,我无法更改.

我成功使用此参数尝试了腻子:
http://athiri.cimds.ri.cmu.edu/files/TcpBridge-putty.jpg

想得到您的帮助!

C ++库具有以下参数:

HI all,

How to develop in C# a program to communicate (send and receive) with this existing C++ library ??

This library is already developed and I can''t change it.

I tried putty with this parameters with success :
http://athiri.cimds.ri.cmu.edu/files/TcpBridge-putty.jpg

Think you for your help !

The C++ library has this parameters :

WSADATA winsock;
	SOCKET listenSocket, clientSocket;
	sockaddr_in socketAddress;

	// Setup WinSock
	if(WSAStartup (0x0202, &winsock) != 0) return;
	if (winsock.wVersion != 0x0202){
		WSACleanup ();
		return;
	}

	// Configure the socket for TCP
	listenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if(listenSocket == INVALID_SOCKET){
		MessageBox(NULL, "Socket failed", "VBS2 TCP Bridge", MB_OK);	
		return;
	}

	// Bind to port
	memset(&socketAddress, 0, sizeof(sockaddr_in));
	socketAddress.sin_family = AF_INET;
	socketAddress.sin_port = htons(SERVER_PORT);
	socketAddress.sin_addr.s_addr = htonl(INADDR_ANY);
	if (bind(listenSocket, (LPSOCKADDR)&socketAddress, sizeof(socketAddress)) == SOCKET_ERROR){
	  MessageBox(NULL, "Bind Failed", "VBS2 TCP Bridge", MB_OK);
	  WSACleanup();
	  return;
	}

推荐答案

签出
Check out TcpListener[^], there is two good examples on how to use TcpListener and TcpClient.

TcpListener server=null;

// Setup listener, accept on any IP address on local computer on TCP port 13000.
server = new TcpListener(IPAddress.Any, 13000);

// Start to listen for clients
server.Start();

// Wait her for incomming connections.
TcpClient client = server.AcceptTcpClient();


这篇关于C#与C ++ dll的TCP连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆