客户端程序运行时总是有10047错误
我的客户端程序中“连接”按钮的响应程序段为 (运行时出现了10047号错误):
case IDC_CONNECT:
WSAStartup(0x0202, &wsadat);
s=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
host= gethostbyname("YH");
CopyMemory(&server.sin_addr , host->h_addr_list[0],host->h_length );
connect(s, (struct sockaddr *)&server, sizeof(server));
//WSAGetLastError()
iError=WSAGetLastError();
wsprintf(&cError, (char *)&itoc, iError);
SetDlgItemText(hDlg, IDC_ERROR, &cError);
return false;
我的客户端程序的完整源码为 (呵,有点长了) :
#include "stdafx.h"
#include "resource.h"
#include "winuser.h"
#include <winbase.h>
#include "winsock2.h"
HINSTANCE hIns;
BOOL WINAPI MainDlg(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
hIns=hInstance;
DialogBox(hInstance,MAKEINTRESOURCE(IDD_CLIENT),NULL,(DLGPROC)MainDlg);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
BOOL WINAPI MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
WSADATA wsadat;
SOCKET s;
HOSTENT *host;
struct sockaddr_in server;
int port=5150, iError=0, addlen;
struct sockaddr clientaddr;
char cError, itoc[]="%d";
switch(message)
{
case WM_CLOSE:
EndDialog(hDlg,0);
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_CONNECT:
WSAStartup(0x0202, &wsadat);
s=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
host= gethostbyname("SZ");
CopyMemory(&server.sin_addr , host->h_addr_list[0],host->h_length );
connect(s, (struct sockaddr *)&server, sizeof(server));
//WSAGetLastError()
iError=WSAGetLastError();
wsprintf(&cError, (char *)&itoc, iError);
SetDlgItemText(hDlg, IDC_ERROR, &cError);
return false;
case IDC_EXIT:
WSACleanup();
SendMessage(hDlg, WM_CLOSE, 0, 0);
}
}
return false;
}
//END
case IDC_CONNECT:
WSAStartup(0x0202, &wsadat);
s=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
host= gethostbyname("YH");
CopyMemory(&server.sin_addr , host->h_addr_list[0],host->h_length );
connect(s, (struct sockaddr *)&server, sizeof(server));
//WSAGetLastError()
iError=WSAGetLastError();
wsprintf(&cError, (char *)&itoc, iError);
SetDlgItemText(hDlg, IDC_ERROR, &cError);
return false;
我的客户端程序的完整源码为 (呵,有点长了) :
#include "stdafx.h"
#include "resource.h"
#include "winuser.h"
#include <winbase.h>
#include "winsock2.h"
HINSTANCE hIns;
BOOL WINAPI MainDlg(HWND,UINT,WPARAM,LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
hIns=hInstance;
DialogBox(hInstance,MAKEINTRESOURCE(IDD_CLIENT),NULL,(DLGPROC)MainDlg);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
BOOL WINAPI MainDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
WSADATA wsadat;
SOCKET s;
HOSTENT *host;
struct sockaddr_in server;
int port=5150, iError=0, addlen;
struct sockaddr clientaddr;
char cError, itoc[]="%d";
switch(message)
{
case WM_CLOSE:
EndDialog(hDlg,0);
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_CONNECT:
WSAStartup(0x0202, &wsadat);
s=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
host= gethostbyname("SZ");
CopyMemory(&server.sin_addr , host->h_addr_list[0],host->h_length );
connect(s, (struct sockaddr *)&server, sizeof(server));
//WSAGetLastError()
iError=WSAGetLastError();
wsprintf(&cError, (char *)&itoc, iError);
SetDlgItemText(hDlg, IDC_ERROR, &cError);
return false;
case IDC_EXIT:
WSACleanup();
SendMessage(hDlg, WM_CLOSE, 0, 0);
}
}
return false;
}
//END
...全文
相关推荐
2021-2022计算机二级等级考试试题及答案No.10047.docx
2021-2022计算机二级等级考试试题及答案No.10047.docx
windows socket错误码及出错原因
windows socket错误码及出错原因,可以参考一下。也可MSDN。
socket错误代码对应表
Socket错误代码对应表 提示: 在命令提示符下输入:net helpmsg 1xxxx 就能够得到Windows系统提供的错误提示的详细解释。 出现网络联机错误Socket error #11001 表示您的计算机无法连上服务器,请检查您的Proxy设定以及Proxy相关账号,或暂时取消您防毒软件的「个人防火墙」。 · 出现网络联机错误Socket error #11004 应该是网络联机状态问题,请用户检查网络联机是否正常。 · 出现网络联机错误Socket error #10060 Connection Timed Out 表示您与服务器发生联机逾时错误,请检查您的Proxy相关设定,以及Proxy Server是否已将SSL 443 port打开。
socket常见错误代码解析.pdf
socket常见错误代码解析.pdf
Winsock错误代码 txt
Winsock错误代码 txt 的 希望对大家有所帮助...


网络编程
