TcpSrv.cpp ( File view )

  • By xzy6218372 2014-01-04
  • View(s):361
  • Download(s):2
  • Point(s): 2
			#include <Winsock2.h>
#include <stdio.h>

void main()
{

	//加载套接字
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;
	
	wVersionRequested=MAKEWORD(1,1);
	
	err=WSAStartup(wVersionRequested,&wsaData);
	if(err!=0)
	{

		return;
	
}
	
	if(LOBYTE(wsaData.wVersion)!=1||
		HIBYTE(wsaData.wVersion)!=1)
	{

		WSACleanup();//终止WINSocket
		return;
	
}
	//创建套接字
	SOCKET sockSrv=socket(AF_INET,SOCK_STREAM,0);//是基于TCP的,所以要流式套接字,第三参数是自动选择协议

	//绑定本地地址和端口上
	SOCKADDR_IN addrSrv;//地址结构体的变量
	addrSrv.sin_addr.S_un.S_addr=htonl(INADDR_ANY);//使用的是网络字节序
	addrSrv.sin_family=AF_INET;
	addrSrv.sin_port=htons(6000);//设置端口号,要超过1024的端口号
	
	bind(sockSrv,(SOCKADDR*)&addrSrv,sizeof(SOCKADDR));
	
	listen(sockSrv,5);
	
	SOCKADDR_IN addrClient;//接收客户端的客户信息
	int len=sizeof(SOCKADDR);
	
	
	
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
TcpClient.exe168.07 kB16-10-13|15:25
TcpClient.ilk176.62 kB16-10-13|15:25
TcpClient.obj12.97 kB16-10-13|15:24
TcpClient.pch3.47 MB28-11-13|20:52
TcpClient.pdb337.00 kB16-10-13|15:25
TcpSrv.obj13.61 kB28-11-13|20:52
vc60.idb137.00 kB28-11-13|20:53
vc60.pdb76.00 kB28-11-13|20:52
TcpClient.cpp934.00 B16-10-13|15:17
TcpClient.dsp4.28 kB17-10-13|20:05
TcpClient.dsw722.00 B16-10-13|15:19
TcpClient.ncb33.00 kB28-11-13|21:23
TcpClient.opt52.50 kB28-11-13|21:23
TcpSrv.exe168.09 kB28-11-13|20:53
TcpSrv.ilk179.39 kB28-11-13|20:53
TcpSrv.obj13.58 kB28-11-13|20:53
TcpSrv.pch3.47 MB28-11-13|20:53
TcpSrv.pdb425.00 kB28-11-13|20:53
vc60.idb137.00 kB28-11-13|20:53
vc60.pdb76.00 kB28-11-13|20:53
TcpSrv.cpp1.31 kB18-10-13|10:42
TcpSrv.dsp4.22 kB16-10-13|15:21
TcpSrv.plg1.28 kB28-11-13|20:53
Debug0.00 B17-12-13|16:26
Debug0.00 B17-12-13|16:27
TcpClient0.00 B17-12-13|16:26
TcpSrv0.00 B17-12-13|16:26
TcpSocket0.00 B17-12-13|16:26
...
Sponsored links

TcpSrv.cpp (2.25 MB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D