|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <WinSock2.h>
#include <stdio.h>
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(1, 1);
err = WSAStartup(wVersionRequested, &wsaData);
if (0 != err)
{
return;
}
if (LOBYTE(wsaData.wVersion != 1) || HIBYTE(wsaData.wVersion) != 1)
{
WSACleanup();
return;
}
SOCKET sockSrv = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(6253);
bind(sockSrv, (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
listen(sockSrv, 5);
SOCKADDR_IN addrClient;
int len;
len = sizeof(SOCKADDR);
while (1)
{
SOCKET sockConn = accept(sockSrv, (sockaddr*)&addrClient, &len);
char sendBuf[100] = {0};
sprintf(sendBuf, "welcome %s to http://www.sunxin.org", inet_ntoa(addrClient.sin_addr));
send(sockConn, sendBuf, strlen(sendBuf) + 1, 0);
char recvBuf[100] = {0};
recv(sockConn, recvBuf, 100, 0);
printf("%s\n", recvBuf);
closesocket(sockConn);
}
}
这是服务器端代码
if(LOBYTE(wsaData.wVersion != 1) || HIBYTE(wsaData.wVersion) != 1)
00DC5070 0F B7 85 5C FE FF FF movzx eax,word ptr [wsaData]
00DC5077 83 F8 01 cmp eax,1
00DC507A 74 0C je main+78h (0DC5088h)
00DC507C C7 85 9C FB FF FF 01 00 00 00 mov dword ptr [ebp-464h],1
00DC5086 EB 0A jmp main+82h (0DC5092h)
00DC5088 C7 85 9C FB FF FF 00 00 00 00 mov dword ptr [ebp-464h],0
00DC5092 8B 8D 9C FB FF FF mov ecx,dword ptr [ebp-464h]
00DC5098 81 E1 FF 00 00 00 and ecx,0FFh
00DC509E 0F B6 D1 movzx edx,cl
00DC50A1 85 D2 test edx,edx
00DC50A3 75 17 jne main+0ACh (0DC50BCh)
00DC50A5 0F B7 85 5C FE FF FF movzx eax,word ptr [wsaData]
00DC50AC C1 E8 08 shr eax,8
00DC50AF 25 FF 00 00 00 and eax,0FFh
00DC50B4 0F B6 C8 movzx ecx,al
00DC50B7 83 F9 01 cmp ecx,1
00DC50BA 74 14 je main+0C0h (0DC50D0h)
{
WSACleanup();
00DC50BC 8B F4 mov esi,esp
00DC50BE FF 15 FC B0 DC 00 call dword ptr [__imp__WSACleanup@0 (0DCB0FCh)]
00DC50C4 3B F4 cmp esi,esp
00DC50C6 E8 70 C0 FF FF call __RTC_CheckEsp (0DC113Bh)
return;
00DC50CB E9 AA 01 00 00 jmp main+26Ah (0DC527Ah)
}
if((LOBYTE(wsaData.wVersion) != 1) || (HIBYTE(wsaData.wVersion) != 1))
001B5070 0F B7 85 5C FE FF FF movzx eax,word ptr [wsaData]
001B5077 25 FF 00 00 00 and eax,0FFh
001B507C 0F B6 C8 movzx ecx,al
001B507F 83 F9 01 cmp ecx,1
001B5082 75 17 jne main+8Bh (01B509Bh)
001B5084 0F B7 85 5C FE FF FF movzx eax,word ptr [wsaData]
001B508B C1 E8 08 shr eax,8
001B508E 25 FF 00 00 00 and eax,0FFh
001B5093 0F B6 C8 movzx ecx,al
001B5096 83 F9 01 cmp ecx,1
001B5099 74 14 je main+9Fh (01B50AFh)
{
WSACleanup();
001B509B 8B F4 mov esi,esp
001B509D FF 15 FC B0 1B 00 call dword ptr [__imp__WSACleanup@0 (01BB0FCh)]
001B50A3 3B F4 cmp esi,esp
001B50A5 E8 91 C0 FF FF call __RTC_CheckEsp (01B113Bh)
return;
001B50AA E9 AA 01 00 00 jmp main+249h (01B5259h)
}
|
|