I am using winsock as a client with about 10 threads.
Each thread has it’s own unique connection to the same host and port.
All threads are connected and they all need to read a certain amount of bytes
at the same time. I see that I can only use 1 recv function at a time, why is that?
function RecvThread ( p : pointer ) : Integer; stdcall;
var
Sock : TSocket;
Addr : TSockAddrIn;
res : Integer;
begin
Addr.sin_family := AF_INET;
Addr.sin_port := htons(8080);
Sock := Socket(AF_INET, SOCK_STREAM, 0);
Addr.sin_addr.S_addr := INET_ADDR (pchar('localhost'));
if (Connect(Sock, Addr, SizeOf(Addr)) = 0) then begin
while true do begin
res := recv (sock, buff, 99999, 0); // just example
if (res < 0) or (res = INVALID_SOCKET) then break;
end;
// Free Stuff, Disconnect, etc...
end;
Is the server capable of writing simultaneously to 10 clients? Does 1 recv function at a time mean that each client receives data in sequence or that only one client works at all and the other 9 fail?
You could try creating a chargen server to test against. Run 10 copies of that on different ports (so threads in the chargen server don’t need to be tested/considered) and connect the clients to one port each.