Question Locked

How the Hell do I get Visual C .net to open a TCP socket connection

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

What is a "Bullet-proof" method of setting up a SOCKET using Visual C++.net??? I've been trying to run it with my code but I KEEP getting an ERROR when it RUNs. The code is as follows:

String^ remoteName = "localhost";

Socket^ clientSocket = gcnew Socket( AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::Tcp );
System::Net::IPAddress^ ipAddress = System::Net::Dns::GetHostEntry("localhost")->AddressList[0];
IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddress, 1800 );
clientSocket->Connect( ipEndPoint );

I'm using Visual C++.net on Visual Studio.net 2005 Frameworks (3.0).

*** Note: ***
I can NOT use the "Dns::Resolve" command since its been obsoleted...

2 replies

by ic-it

I haven't played with .Net yet, but did find these clues;

Windows
has implented their own version very similar to the BSD sockets API.
The include file for this is simply . You will also have
to link the WS2_32.lib to your program. This can be done in the
project settings menu. Another issue of importance is the way that
the API is implemented. Even though it is very similar to coding
sockets on other systems, it still has its differences. For example
you must call WSAStartup() before you even call socket(). Once you
see the code however you should be more than comfortable with coding
sockets in windows.

And a potentially nice reference site; (It initially looks like a C tutorial, but has a special .Net section dedicated to the winsock).

http://www.tenouk.com/cnwinsock2tutorials.html

This discussion is closed to new replies.