服務器端對一個客戶端來了就開啟一個工作線程,最多可接受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-=
表示是很簡陋的寫法,肯定還是有問題的,同步的地方沒怎麼想清楚,測試代碼可以看上一篇的介紹,好吧,今天暫時先寫到這裡,尼瑪,公司寫神碼軟件申請書,搓的一逼。