MCPcopy Create free account
hub / github.com/LARG/HFO / startServer

Method startServer

src/agent.cpp:254–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252}
253
254void Agent::startServer(int server_port) {
255 std::cout << "[Agent Server] Starting Server on Port " << server_port << std::endl;
256 struct sockaddr_in serv_addr, cli_addr;
257 sockfd = socket(AF_INET, SOCK_STREAM, 0);
258 if (sockfd < 0) {
259 error("[Agent Server] ERROR opening socket");
260 }
261 bzero((char *) &serv_addr, sizeof(serv_addr));
262 serv_addr.sin_family = AF_INET;
263 serv_addr.sin_addr.s_addr = INADDR_ANY;
264 serv_addr.sin_port = htons(server_port);
265 if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
266 error("[Agent Server] ERROR on binding");
267 }
268 listen(sockfd, 5);
269 socklen_t clilen = sizeof(cli_addr);
270 std::cout << "[Agent Server] Waiting for client to connect... " << std::endl;
271 newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
272 if (newsockfd < 0) {
273 error("[Agent Server] ERROR on accept");
274 }
275 std::cout << "[Agent Server] Connected" << std::endl;
276 server_running = true;
277}
278
279void Agent::clientHandshake() {
280 // Send float 123.2345

Callers

nothing calls this directly

Calls 1

errorFunction · 0.70

Tested by

no test coverage detected