程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 一個worker thread服務一個客戶端

一個worker thread服務一個客戶端

編輯:C++入門知識

服務器端對一個客戶端來了就開啟一個工作線程,最多可接受64個。

具體看代碼:

 once<winsock.h><stdio.h>

 comment(lib, "ws2_32.lib")

 MaxClient 64

~MyTCPSocket( Bind(unsigned aPost, * Listen( aBacklog= Connect(unsigned aPost, * Send( *

*-&~MyTCPSocket(& ( i =; i < m_TotClient;++ (NULL !=&&= MAKEWORD(, = WSAStartup(wVersionRequested, & (iResult !=   = (INVALID_SOCKET == = *)&reuseaddr,  MyTCPSocket::Bind(unsigned aPost, * sockaddr_in server_addr;    
    server_addr.sin_family = AF_INET;         
    server_addr.sin_port = htons(aPost);     
    server_addr.sin_addr.s_addr = inet_addr(aAdress); 
    memset(server_addr.sin_zero, ,  (- == bind(m_Socket,( sockaddr *)&server_addr,  nRecvBuf =  * ; 
     (setsockopt(m_Socket,SOL_SOCKET,SO_RCVBUF,( *)&nRecvBuf,()) == -  MyTCPSocket::Connect( unsigned aPost, *=== (- == connect(m_Socket,( sockaddr *)&lsockaddr_in,   MyTCPSocket::Listen(  aBacklog (- ==   MyTCPSocket::Send(  * (- == send(m_Socket,aBuf,strlen(aBuf)+,  
      (- ==  ( lAddrLen =  (m_TotClient == MaxClient-&++m_TotClient] = accept(m_Socket, (sockaddr*)&m_SockClientaddrIn,&* lpPara = ->m_pMyTCPSocket = ->m_CurSocket =&= ::CreateThread(NULL, , WorkerFun,PVOID(lpPara), , & (NULL == * lpPara = (Para** lTCPSocket = lpPara-> (lpPara->m_CurSocket == ( lBuf[ lLength = = recv(lpPara->m_CurSocket,lBuf,(lBuf), (SOCKET_ERROR == lLength ||  ==->  lBegin =  lEnd =  (;lEnd < lLength;++ ( == lData[ lLen = lEnd-+lBegin,lLen+= lEnd+ (lEnd < lData[+lBegin,lEnd-=  

表示是很簡陋的寫法,肯定還是有問題的,同步的地方沒怎麼想清楚,測試代碼可以看上一篇的介紹,好吧,今天暫時先寫到這裡,尼瑪,公司寫神碼軟件申請書,搓的一逼。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved