0
我有一個c#gui,當點擊一個按鈕時調用引用的C++ dll。在C++ DLL我有以下代碼Winsock連接失敗,錯誤10049
SOCKADDR_IN server;
server.sin_port=htons (54321);
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
// Connect to server.
int iResult = connect(Socket, (SOCKADDR *) & server, sizeof (server));
if (iResult == SOCKET_ERROR) {
long iError = WSAGetLastError();
if (iError == WSAEWOULDBLOCK)
printf("recv failed with error: WSAEWOULDBLOCK\n");
else
printf("recv failed with error: %ld\n", iError);
wprintf(L"connect function failed with error: %ld\n", WSAGetLastError());
iResult = closesocket(Socket);
if (iResult == SOCKET_ERROR)
wprintf(L"closesocket function failed with error: %ld\n", WSAGetLastError());
WSACleanup();
return 1;
}
在C#調用程序的DLL調用和連接通過Winsock2的在DLL中做之前,我有
再經過IPAddress localAddr = IPAddress.Parse("127.0.0.1");
TcpListener serverSocket = new TcpListener(localAddr,54321);
int requestCount = 0;
TcpClient clientSocket = default(TcpClient);
serverSocket.Start();
的dll是叫我做
//調用DLL運行連接代碼
clientSocket = serverSocket.AcceptTcpClient();//hangs up here because dll can't Connect.
在C當我一步++ DLL在連接我得到錯誤10049,這是 WSAEADDRNOTAVAIL。
什麼我在連接做錯了電話?在msdn示例之後,我選擇了54321作爲端口。 謝謝!
的感謝!這讓事情奏效!非常感激! – user2192008