Skip to content

Commit 96dcf01

Browse files
committed
Server port fixed. Console input is hidden now.
1 parent fcdca28 commit 96dcf01

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

server/ClientSession.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ namespace simpleApp
4141

4242
std::string addressToString(sockaddr_in& address)
4343
{
44-
uint32_t addressConverted = ntohl(address.sin_addr.s_addr);
4544
auto portConverted = ntohs(address.sin_port);
4645

47-
uint8_t* addressByBytes = reinterpret_cast<uint8_t*>(&addressConverted);
46+
uint8_t* addressByBytes = reinterpret_cast<uint8_t*>(&address.sin_addr.s_addr);
4847

4948
return std::to_string(static_cast<int>(addressByBytes[0])) + std::string(".") +
5049
std::to_string(static_cast<int>(addressByBytes[1])) + std::string(".") +

server/main.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
#include <stdlib.h>
44
#include <unistd.h>
55

6+
#include <stdio.h>
7+
#include <termios.h>
8+
#include <time.h>
9+
#include <sys/ioctl.h>
10+
11+
#include <cstring>
12+
613
#include "Server.hpp"
714

815
simpleApp::Server server = simpleApp::Server();
@@ -17,6 +24,16 @@ void onExit(int s)
1724

1825
int main(int argc, char** argv)
1926
{
27+
// Hide console input
28+
termios orig_term_attr;
29+
termios new_term_attr;
30+
tcgetattr(fileno(stdin), &orig_term_attr);
31+
memcpy(&new_term_attr, &orig_term_attr, sizeof(termios));
32+
new_term_attr.c_lflag &= ~(ECHO | ICANON);
33+
new_term_attr.c_cc[VTIME] = 0;
34+
new_term_attr.c_cc[VMIN] = 0;
35+
tcsetattr(fileno(stdin), TCSANOW, &new_term_attr);
36+
2037
std::cout << "Welcome to the SimpleServer!" << std::endl <<
2138
"For exit press Ctrl+C" << std::endl;
2239

@@ -39,5 +56,5 @@ int main(int argc, char** argv)
3956
return -1;
4057
}
4158

42-
return server.serverLoop(static_cast<uint16_t>(35831));
59+
return server.serverLoop(static_cast<uint16_t>(35830));
4360
}

0 commit comments

Comments
 (0)