Click here to Skip to main content
15,908,445 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
	}
Posted
Updated 8-May-11 23:47pm
v2
Comments
Sergey Alexandrovich Kryukov 9-May-11 3:44am    
Where is your question!
--SA
Kim Togo 9-May-11 5:12am    
What is the question?
canard29 9-May-11 12:32pm    
how to do this in C# ? I tried many solution but without success

1 solution

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

C#
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();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900