18 int bytes_payload_total = 0;
20 while (bytes_payload_total < data_size)
23 &buffer[bytes_payload_total],
24 data_size - bytes_payload_total,
27 if (bytes_payload_count == -1)
29 perror(
"Error reading Data!");
32 else if (bytes_payload_count == 0)
34 std::cout <<
"Unexpected end of transmission" << std::endl;
37 bytes_payload_total += bytes_payload_count;
51 int bytes_count = recv(
rc_socket, &buffer[0], 1, 0);
55 std::cout <<
"Socket flushed (" << bytes_total / 1024 <<
" kB)" << std::endl;
58 bytes_total += bytes_count;
66 int error = WSAStartup(0x0202, &w);
74 rc_socket = socket(AF_INET, SOCK_STREAM, 0);
77 handle_socket_errors(
"intitializing Socket");
82 handle_socket_errors(
"setting socket options");
85 address.sin_family = AF_INET;
86 address.sin_addr.s_addr = inet_addr(
ip.c_str());
87 address.sin_port = htons(
port);
89 std::cout <<
"Waiting for incoming connection..." << std::endl;
92 int error_counter = 0;
97 if (error_counter < 1)
99 handle_socket_errors(
"connecting to Socket");
105 std::cout <<
"Connected by " << inet_ntoa(address.sin_addr) <<
"\n";
113 void SocketConnector::handle_socket_errors(
const std::string &raised_at)
116 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
117 NULL, WSAGetLastError(),
118 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
119 (LPWSTR)&s, 0, NULL);
120 std::cout <<
"Error occured while " << raised_at <<
"." << std::endl;
121 fprintf(stderr,
"%S\n", s);
131 void SocketConnector::handle_socket_errors(
const std::string &raised_at)
133 std::cout <<
"Error occured while " << raised_at <<
"." << std::endl;
134 std::cout << std::strerror(errno) << std::endl;
int read_data(char *buffer, int data_size)