#pragma comment(lib, "ws2_32.lib ") using namespace std;DWORD WINAPI ClientThread(LPVOID sockCli_windows socket= socket(af_inet, sock_stream, ipproto_tcp);">
赞
踩
1. tcp服务器端
- #include "stdafx.h"
-
- #include <WINSOCK2.H>
- #include <windows.h>
- #include <iostream>
- #include <string>
-
- #pragma comment(lib, "ws2_32.lib ")
-
- using namespace std;
-
-
- DWORD WINAPI ClientThread(LPVOID sockCliet);
-
- int _tmain(int argc, _TCHAR* argv[])
- {
-
- // 0 --- 加载套接字库
- WSAData wsaData;
- WSAStartup(MAKEWORD(2,2), &wsaData);
-
- // 1 --- 创建套接字
- SOCKET serSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-
- // 2 --- 绑定套接字
- SOCKADDR_IN addrService;
- addrService.sin_family = AF_INET;
- addrService.sin_addr.s_addr = inet_addr("127.0.0.1");
- addrService.sin_port = htons(6000);
- bind(serSock, (sockaddr *)&addrService, sizeof(addrService));
-
- // 3 --- 指定最大同时连接数,开始监听
- listen(serSock, 10);
-
-
- // 4 --- 接受新的连接,创建线程处理本次连接
- while (1)
- {
- SOCKADDR_IN addrClient;
- int n = sizeof(addrClien
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。