随笔分类 -  C++ 多线程与网络

摘要:套接字操作系统管理的进程的套接字表,每一个进程拥有一张套接字表套接字有两种一种是被动套接字(作为Server时),一种是活动套接字(作为Client时)。TCP/IP 协议族 常量 PF_INET =2TCP/IP 地址族 常量 AF_INET =2套接字端点地址一般数据结构struct sockaddr{ //一般结构定义 u_short sa_family; //地址族 char sa_data[14]; //地址};套接字端点地址的精确数据结构定义struct sockaddr_in{ u_short sin_family; //地址类型,值一直都是AF_INET u_short... 阅读全文
posted @ 2013-10-16 12:54 AlexChowG 阅读(470) 评论(0) 推荐(0)
摘要:C++ 11 多线程相关库thread类thread构造方法,支持lambda语句thread(函数名, 函数参数...)成员函数:detach()//不阻塞运行开始线程join()//阻塞主线程,运行线程互斥的实现使用了Mutex 类 阅读全文
posted @ 2013-10-16 12:50 AlexChowG 阅读(167) 评论(0) 推荐(0)
摘要:ntohs =net to host short int 16位htons=host to net short int 16位ntohs =net to host long int 32位htonl=host to net long int 32位简述: 将一个无符号短整形数从网络字节顺序转换为主机字节顺序。 #include u_short PASCAL FAR ntohs( u_short netshort); netshort:一个以网络字节顺序表达的16位数。注释: 本函数将一个16位数由网络字节顺序转换为主机字节顺序。返回值: ntohs()返回... 阅读全文
posted @ 2013-10-16 12:49 AlexChowG 阅读(721) 评论(0) 推荐(0)
摘要:C++多线程需要的库文件windows 下process.h函数:_begingthread(void*(void*) pfunc,unsigned stack, void* funcParam);pfunc为只有一个void类型的指针参数(可以通过强制转换为void*类型)的void返回类型函数指针stack栈大小,一般为0funcParam为pfunc的参数指针,需要强制转换为void*类型使用:int sum(struct param){ return param.a+param.b;}struct param p;_beginthread((void(*)(void*)sum,0,(. 阅读全文
posted @ 2013-10-16 12:48 AlexChowG 阅读(476) 评论(0) 推荐(0)
摘要:在c如果需要编译winsock 程序链接出错xx@的错误在链接参数加入-lwsock32 或者 在头文件第一句加入#pragma comment(lib,"ws2_32.lib")多线程程序 加入 -lpthreadGC2 阅读全文
posted @ 2013-10-16 12:47 AlexChowG 阅读(175) 评论(0) 推荐(0)