Hi,
I have a TCP server that handles more than 100 clients.
I keep getting bottlenecks and i narrowed it down to the send() winsock function.
A send() winsock call sometimes takes 100~300ms to finish.
I i have no clue why but this block from other clients to be served.
Socket initialization code
Accepting codeCode:int ret = WSAStartup(MAKEWORD(2,2), &wsaData); if(ret != 0) { printf("Winsock failed to start.\n"); system("pause"); return; } server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons(52000); sock = socket(AF_INET, SOCK_STREAM, 0); if(sock == INVALID_SOCKET) { printf("Invalid Socket.\n"); system("pause"); return; } if(bind(sock, (sockaddr*)&server, sizeof(server)) != 0) { printf("error"); return; } if(listen(sock, 5) != 0) { printf("error"); return; }
Send function callerCode:sockaddr_in from; int fromlen = sizeof(from); SOCKET sTmpSocket = accept(ServerSock, (struct sockaddr*)&from, &fromlen);
I would like to know how i can fix the delay.Code:void CClient::SendPacket(BYTE* pPacket, DWORD Len) { DWORD ToSendLen = Len; while (ToSendLen) { int iResult = send(this->ClientSocket, (char*)(pPacket + Len - ToSendLen), ToSendLen, 0); if (iResult == SOCKET_ERROR) return; ToSendLen -= iResult; } }
Thank you very much.




Reply With Quote