Still having issues with loading site

This commit is contained in:
Trimutex 2023-10-03 18:34:21 -05:00
parent 42bf316ccb
commit abab69344a
2 changed files with 49 additions and 47 deletions

View File

@ -13,27 +13,30 @@ void TestSockets(int sender_s, int receiver_s) {
std::cout << "Attempting to send data to receiver" << std::endl; std::cout << "Attempting to send data to receiver" << std::endl;
do { do {
buf_len = recv(sender_s, in_buf, BUF_SIZE, 0); buf_len = recv(sender_s, in_buf, BUF_SIZE, 0);
std::cout << "LOG (info) - pipe packet recv size: " << buf_len << std::endl;
if (buf_len == -1) { if (buf_len == -1) {
std::cout << "ERROR (info) - recv" << std::endl; std::cout << "ERROR (info) - recv" << std::endl;
return;
} }
if (buf_len == 0) { continue; } if (buf_len == 0) { break; }
send(receiver_s, in_buf, buf_len, 0); buf_len = send(receiver_s, in_buf, buf_len, 0);
std::cout << "LOG (info) - pipe packet size: " << buf_len << std::endl; std::cout << "LOG (info) - pipe packet send size: " << buf_len << std::endl;
} while (buf_len > 0); } while (buf_len == BUF_SIZE);
std::cout << "Sent data to receiver" << std::endl; std::cout << "Sent data to receiver" << std::endl;
// Pass response along from server to browser // Pass response along from server to browser
std::cout << "Attempting to send to browser" << std::endl; std::cout << "Attempting to send to browser" << std::endl;
do { do {
buf_len = recv(receiver_s, out_buf, BUF_SIZE, 0); buf_len = recv(sender_s, out_buf, BUF_SIZE, 0);
std::cout << "LOG (info) - proxy packet recv size: " << buf_len << std::endl;
if (buf_len == -1) { if (buf_len == -1) {
std::cout << "ERROR (info) - recv" << std::endl; std::cout << "ERROR (info) - recv" << std::endl;
break; return;
} }
if (buf_len == 0) { continue; } if (buf_len == 0) { break; }
send(sender_s, out_buf, buf_len, 0); buf_len = send(receiver_s, out_buf, buf_len, 0);
std::cout << "LOG (info) - proxy packet size: " << buf_len << std::endl; std::cout << "LOG (info) - proxy packet send size: " << buf_len << std::endl;
} while (buf_len > 0); } while (buf_len == BUF_SIZE);
std::cout << "Sent to browser" << std::endl; std::cout << "Sent to browser" << std::endl;
close(sender_s); close(sender_s);
close(receiver_s); close(receiver_s);
@ -55,7 +58,7 @@ void PipeSockets(int sender_s, int receiver_s) {
if (buf_len == 0) { break; } if (buf_len == 0) { break; }
buf_len = send(receiver_s, in_buf, buf_len, 0); buf_len = send(receiver_s, in_buf, buf_len, 0);
std::cout << "LOG (info) - pipe packet send size: " << buf_len << std::endl; std::cout << "LOG (info) - pipe packet send size: " << buf_len << std::endl;
} while (buf_len < BUF_SIZE); } while (buf_len == BUF_SIZE);
std::cout << "Sent data to receiver" << std::endl; std::cout << "Sent data to receiver" << std::endl;
} }
@ -70,13 +73,16 @@ void ProxySockets(int sender_s, int receiver_s) {
buf_len = recv(sender_s, out_buf, BUF_SIZE, 0); buf_len = recv(sender_s, out_buf, BUF_SIZE, 0);
std::cout << "LOG (info) - proxy packet recv size: " << buf_len << std::endl; std::cout << "LOG (info) - proxy packet recv size: " << buf_len << std::endl;
if (buf_len == -1) { if (buf_len == -1) {
std::cout << "ERROR (info) - recv" << std::endl; std::cout << "ERROR (info) - recv -1" << std::endl;
return;
}
if (buf_len == 0) {
std::cout << "ERROR (info) - recv 0" << std::endl;
return; return;
} }
if (buf_len == 0) { break; }
buf_len = send(receiver_s, out_buf, buf_len, 0); buf_len = send(receiver_s, out_buf, buf_len, 0);
std::cout << "LOG (info) - proxy packet send size: " << buf_len << std::endl; std::cout << "LOG (info) - proxy packet send size: " << buf_len << std::endl;
} while (buf_len < BUF_SIZE); } while (buf_len == BUF_SIZE);
std::cout << "Sent to browser" << std::endl; std::cout << "Sent to browser" << std::endl;
close(sender_s); close(sender_s);
close(receiver_s); close(receiver_s);

View File

@ -121,46 +121,42 @@ void ClientRequest(int client_s) {
// Receive the GET request from the Web browser // Receive the GET request from the Web browser
retcode = recv(client_s, in_buf, BUF_SIZE, 0); retcode = recv(client_s, in_buf, BUF_SIZE, 0);
if (retcode == -1) { std::cerr << "ERROR (info) - recv" << std::endl; }
// Handle the GET if there is one (see note #3 in the header) // Handle the GET if there is one (see note #3 in the header)
if (retcode != -1) // Parse out the filename from the GET request
{ strtok(in_buf, " ");
// Parse out the filename from the GET request file_name = strtok(NULL, " ");
strtok(in_buf, " ");
file_name = strtok(NULL, " ");
// Open the requested file // Open the requested file
// - Start at 2nd char to get rid of leading "\" // - Start at 2nd char to get rid of leading "\"
#ifdef WIN #ifdef WIN
fh = open(&file_name[1], O_RDONLY | O_BINARY, S_IREAD | S_IWRITE); fh = open(&file_name[1], O_RDONLY | O_BINARY, S_IREAD | S_IWRITE);
#endif #endif
#ifdef UNIX #ifdef UNIX
fh = open(&file_name[1], O_RDONLY, S_IREAD | S_IWRITE); fh = open(&file_name[1], O_RDONLY, S_IREAD | S_IWRITE);
#endif #endif
// Generate and send the response (404 if could not open the file) // Generate and send the response (404 if could not open the file)
if (fh == -1) if (fh == -1)
{ {
printf("File %s not found - sending an HTTP 404 \n", &file_name[1]); printf("File %s not found - sending an HTTP 404 \n", &file_name[1]);
strcpy(out_buf, NOTOK_404); strcpy(out_buf, NOTOK_404);
send(client_s, out_buf, strlen(out_buf), 0); send(client_s, out_buf, strlen(out_buf), 0);
strcpy(out_buf, MESS_404); strcpy(out_buf, MESS_404);
send(client_s, out_buf, strlen(out_buf), 0); send(client_s, out_buf, strlen(out_buf), 0);
} } else {
else printf("File %s is being sent \n", &file_name[1]);
{ if (strstr(file_name, ".gif") != NULL)
printf("File %s is being sent \n", &file_name[1]); strcpy(out_buf, OK_IMAGE);
if (strstr(file_name, ".gif") != NULL) else
strcpy(out_buf, OK_IMAGE); strcpy(out_buf, OK_TEXT);
else send(client_s, out_buf, strlen(out_buf), 0);
strcpy(out_buf, OK_TEXT); do {
send(client_s, out_buf, strlen(out_buf), 0); buf_len = read(fh, out_buf, BUF_SIZE);
do { buf_len = send(client_s, out_buf, buf_len, 0);
buf_len = read(fh, out_buf, BUF_SIZE); } while (buf_len == BUF_SIZE);
send(client_s, out_buf, buf_len, 0); close(fh);
} while (buf_len > 0); }
close(fh);
}
}
// Close the client socket and end the thread // Close the client socket and end the thread
close(client_s); close(client_s);
} }