資源簡介
《精通Windows Sockets網絡開發:基于Visual C++實現》由淺入深、循序漸進地講解如何使用WindowsSockets開發網絡應用程序。WindowsSockets是當前主要的網絡開發技術之一。《精通Windows Sockets網絡開發:基于Visual C++實現》內容包括準備開發環境、TCP/IP基本介紹、Windows套接字基礎、協議特征、基本TCP套接字編程、基本UDP套接字編程、套接字選項、套接字阻塞模式開發、套接字非阻塞模式開發、Select模型開發、WSAAsyncSelect模型開發、WSAEventSelect模型開發、重疊I/O模型開發和完成端口模型開發

代碼片段和文件信息
//?Client.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#define BUF_SZIE 64
#include?“winsock2.h“
#pragma?comment(lib?“ws2_32.lib“)
int?main(int?argc?char*?argv[])
{
WSADATA wsd; //WSADATA變量
SOCKET sHost; //服務器套接字
SOCKADDR_IN servAddr; //服務器地址
char buf[BUF_SZIE]; //接收數據緩沖區
int retVal; //返回值
//初始化套結字動態庫
if?(WSAStartup(MAKEWORD(22)?&wsd)?!=?0)
{
printf(“WSAStartup?failed!\n“);
return?-1;
}
//創建套接字
sHost?=?socket(AF_INET?SOCK_STREAM?IPPROTO_TCP);
if(INVALID_SOCKET?==?sHost)
{
printf(“socket?failed!\n“);
WSACleanup();//釋放套接字資源
return??-1;
}
//設置服務器地址
servAddr.sin_family?=AF_INET;
servAddr.sin_addr.s_addr?=?inet_addr(“127.0.0.1“);
servAddr.sin_port?=?htons((short)4999);
int nServAddlen??=?sizeof(servAddr);
//連接服務器
retVal=connect(sHost(LPSOCKADDR)&servAddr?sizeof(servAddr));
if(SOCKET_ERROR?==?retVal)
{
printf(“connect?failed!\n“);
closesocket(sHost); //關閉套接字
WSACleanup(); //釋放套接字資源
return?-1;
}
//向服務器發送數據
ZeroMemory(buf?BUF_SZIE);
strcpy(buf?“MyTCP“);
retVal?=?send(sHost?buf?strlen(buf)?0);
if?(SOCKET_ERROR?==?retVal)
{
printf(“send?failed!\n“);
closesocket(sHost); //關閉套接字
WSACleanup(); //釋放套接字資源
return?-1;
}
//退出
closesocket(sHost); //關閉套接字
WSACleanup(); //釋放套接字資源
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1507??2008-01-30?15:17??17911\03\3.5\TCP\Client\Client.cpp
?????文件???????4536??2008-01-30?11:35??17911\03\3.5\TCP\Client\Client.dsp
?????文件????????293??2008-01-30?11:35??17911\03\3.5\TCP\Client\StdAfx.cpp
?????文件????????769??2008-01-30?11:35??17911\03\3.5\TCP\Client\StdAfx.h
?????文件???????2130??2008-03-07?10:56??17911\03\3.5\TCP\Server\Server.cpp
?????文件???????4536??2008-01-30?11:34??17911\03\3.5\TCP\Server\Server.dsp
?????文件????????734??2008-01-30?15:35??17911\03\3.5\TCP\Server\Server.dsw
?????文件????????293??2008-01-30?11:34??17911\03\3.5\TCP\Server\StdAfx.cpp
?????文件????????769??2008-01-30?11:34??17911\03\3.5\TCP\Server\StdAfx.h
?????文件???????1282??2008-01-30?15:41??17911\03\3.7\UDP\Client\Client.cpp
?????文件???????4536??2008-01-30?09:13??17911\03\3.7\UDP\Client\Client.dsp
?????文件????????293??2008-01-30?09:13??17911\03\3.7\UDP\Client\StdAfx.cpp
?????文件????????769??2008-01-30?09:13??17911\03\3.7\UDP\Client\StdAfx.h
?????文件???????5232??2008-01-30?17:41??17911\03\3.7\UDP\Example.cpp
?????文件???????4548??2008-01-28?21:10??17911\03\3.7\UDP\Example.dsp
?????文件????????931??2008-01-30?09:13??17911\03\3.7\UDP\Example.dsw
?????文件????????583??2008-02-03?08:10??17911\03\3.7\UDP\Example.positions
?????文件???????2955??2008-01-30?23:34??17911\03\3.7\UDP\Server\Server.cpp
?????文件???????4536??2008-01-30?09:13??17911\03\3.7\UDP\Server\Server.dsp
?????文件????????734??2008-03-07?13:57??17911\03\3.7\UDP\Server\Server.dsw
?????文件????????293??2008-01-30?09:13??17911\03\3.7\UDP\Server\StdAfx.cpp
?????文件????????769??2008-01-30?09:13??17911\03\3.7\UDP\Server\StdAfx.h
?????文件????????294??2008-01-28?21:10??17911\03\3.7\UDP\StdAfx.cpp
?????文件????????769??2008-01-28?21:10??17911\03\3.7\UDP\StdAfx.h
????..A..H.????????10??2007-10-23?00:59??17911\04\4.4\Server\Desktop_.ini
?????文件???????6565??2007-11-01?19:16??17911\04\4.4\Server\Server.cpp
?????文件???????4474??2007-10-29?16:50??17911\04\4.4\Server\Server.dsp
?????文件????????537??2008-03-07?14:04??17911\04\4.4\Server\Server.dsw
?????文件????????293??2007-09-18?13:14??17911\04\4.4\Server\StdAfx.cpp
?????文件????????769??2007-09-18?13:14??17911\04\4.4\Server\StdAfx.h
............此處省略322個文件信息
- 上一篇:基于opencv人眼定位算法C++工程
- 下一篇:給予c++的多線程
評論
共有 條評論