One worker thread serves one client

Source: Internet
Author: User

The server starts a working thread when it comes to a client. A maximum of 64 worker threads can be opened.

Specific Code:

 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-=  

It indicates that the writing method is very simple and there must be a problem. I don't have much idea about the synchronization. I can check the test code in the previous article. Well, I will write it here today, Nima, the company was forced to write an application for the CAPTCHA software.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.