一、有连接编程TCP
》》服务器编写流程
1-创建套接字(socket)
2-服务绑定(bind)
3-服务侦听(listen)
4-处理新连接(accept)
5-数据收发(recv/send)
6-套接字关闭(close)
》》客户端编写流程
1-客户端套接字创建(socket)
2-发起连接(connect)
3-数据发收(send/recv)
4-套接字关闭(close)
server---------------------------------
//TCP 面向连接的编程
#include<iostream>
#include<windows.h>
using namespace std;
#pragma comment(lib,"ws2_32.lib")//静态库
void main()
{
// WSAStartup 协商版本//
//该程序功能是让程序能在Windows上面运行,使之和Linux之上运行一样
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return;
}
/* Confirm that the