version 1.16, 2005/02/22 06:33:40
|
version 1.17, 2005/02/23 04:24:09
|
|
|
| |
hp = gethostbyname("localhost"); | hp = gethostbyname("localhost"); |
| |
while(*serverPort == 0) ; |
while(*serverPort == 0) |
|
; |
| |
// network code here | // network code here |
server.sin_family = AF_INET; | server.sin_family = AF_INET; |
|
|
WSACleanup(); | WSACleanup(); |
exit(0); | exit(0); |
} | } |
|
printf("client starting data transfer\n"); |
while( totCharsReceived < TEST_DATA_SIZE ) { | while( totCharsReceived < TEST_DATA_SIZE ) { |
numCharsReceived = recv(sock, buf, 1000, 0); | numCharsReceived = recv(sock, buf, 1000, 0); |
ok( numCharsReceived > 0, "socket was closed unexpectedly" ); | ok( numCharsReceived > 0, "socket was closed unexpectedly" ); |
|
|
ok( memSame, "data integrity lost during transfer" ); | ok( memSame, "data integrity lost during transfer" ); |
| |
totCharsReceived += numCharsReceived; | totCharsReceived += numCharsReceived; |
|
printf("received %d chars\n", numCharsReceived); |
} | } |
|
printf("client data transfer completed\n"); |
| |
trace("blocking client done\n"); | trace("blocking client done\n"); |
clientsDone++; | clientsDone++; |
} | } |
| |
void ProcessConnection(struct ServerThread t) |
void ProcessConnection(struct ServerThread *t) |
{ | { |
// this will handle all connections to the server, it's in its own function to allow for multithreading | // this will handle all connections to the server, it's in its own function to allow for multithreading |
int bClosed; | int bClosed; |
bClosed = close(t.ConnectedSocket); |
int totCharsSent = 0; |
|
int numCharsSent; |
|
const int charsPerSend = 2000; |
|
|
|
printf("server starting data transfer\n"); |
|
while( totCharsSent < TEST_DATA_SIZE ) { |
|
numCharsSent = send(t->ConnectedSocket, testData+totCharsSent, charsPerSend, 0); |
|
//ok( numCharsSent != SOCKET_ERROR, "socket error" ); |
|
if(numCharsSent == SOCKET_ERROR) { |
|
printf("error code: %d",WSAGetLastError()); |
|
} |
|
totCharsSent += numCharsSent; |
|
printf("sent %d block\n", numCharsSent); |
|
} |
|
printf("server data transfer completed\n"); |
|
|
|
bClosed = close(t->ConnectedSocket); |
//ok(bClosed,"Error closing socket"); | //ok(bClosed,"Error closing socket"); |
} | } |
| |
|
|
int ListenReturn; | int ListenReturn; |
| |
StartNetworkApp(SOCK_STREAM, &sock, &server); | StartNetworkApp(SOCK_STREAM, &sock, &server); |
*port = server.sin_port; |
|
| |
Threads = malloc(sizeof(struct ServerThread) * NUM_CLIENTS); | Threads = malloc(sizeof(struct ServerThread) * NUM_CLIENTS); |
memset(Threads, 0, sizeof(struct ServerThread) * NUM_CLIENTS); | memset(Threads, 0, sizeof(struct ServerThread) * NUM_CLIENTS); |
| |
ListenReturn = listen(sock, 5); |
ListenReturn = listen(sock, NUM_CLIENTS); |
ok(ListenReturn != SOCKET_ERROR, "error listening on socket"); | ok(ListenReturn != SOCKET_ERROR, "error listening on socket"); |
| |
for (ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) |
*port = server.sin_port; |
{ |
|
|
for (ThreadIndex = 0; ThreadIndex < NUM_CLIENTS; ThreadIndex++) { |
Threads[ThreadIndex].ConnectedSocket = accept(sock, (SOCKADDR *) &Threads[ThreadIndex].Client, &sizeofSOCKADDR_IN); // this can be modified to include the address of the remote socket | Threads[ThreadIndex].ConnectedSocket = accept(sock, (SOCKADDR *) &Threads[ThreadIndex].Client, &sizeofSOCKADDR_IN); // this can be modified to include the address of the remote socket |
ok(Threads[ThreadIndex].ConnectedSocket != INVALID_SOCKET, "error accepting socket"); | ok(Threads[ThreadIndex].ConnectedSocket != INVALID_SOCKET, "error accepting socket"); |
| |
Threads[ThreadIndex].ServerThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &ProcessConnection, &(Threads[ThreadIndex].ConnectedSocket), 0, &Threads[ThreadIndex].ServerThreadID); |
Threads[ThreadIndex].ServerThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &ProcessConnection, &Threads[ThreadIndex], 0, &Threads[ThreadIndex].ServerThreadID); |
} | } |
| |
// network code here | // network code here |
| |
|
while (clientsDone != NUM_CLIENTS) |
|
; |
|
|
free(Threads); | free(Threads); |
trace("blocking server done\n"); | trace("blocking server done\n"); |
} | } |