Executing the client I get : client connect failed. connection request timed out
I've put the server code in a Cloud VPS with IP Address: aaa.aaa.a.aaa :
(base) root@WorldMap:~/netcodeServer# cat CMakeLists.txt
cmake_minimum_required(VERSION 3.15...3.31)
project(NetCodeServer)
include(CMakePrintHelpers)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
# https://github.com/robinlinden/libsodium-cmake?tab=readme-ov-file#using-in-your-project
# https://www.tldrlegal.com/license/isc-license
FetchContent_Declare(Sodium
GIT_REPOSITORY https://github.com/robinlinden/libsodium-cmake.git
GIT_TAG e5b985ad0dd235d8c4307ea3a385b45e76c74c6a # HEAD, last updated at 2025-04-13
)
set(SODIUM_DISABLE_TESTS ON)
FetchContent_MakeAvailable(Sodium)
add_executable(${PROJECT_NAME}
src/netcode/netcode.c
src/server.c
)
target_include_directories(${PROJECT_NAME} PUBLIC
src/netcode/include
)
target_link_libraries (${PROJECT_NAME} PUBLIC
sodium
)
Server side code :
(base) root@WorldMap:~/netcodeServer/src# ls -lah
total 20K
drwxr-xr-x 3 root root 4.0K Jun 5 18:27 .
drwxr-xr-x 4 root root 4.0K Jun 5 18:27 ..
drwxr-xr-x 3 root root 4.0K Jun 5 15:35 netcode
-rw-r--r-- 1 root root 4.6K Jun 5 18:27 server.c
where server.c is taken from here: https://github.com/mas-bandwidth/netcode/blob/main/server.c
while netcode.h and netcode.c :
(base) root@WorldMap:~/netcodeServer/src/netcode# ls -lah
total 332K
drwxr-xr-x 3 root root 4.0K Jun 5 15:35 .
drwxr-xr-x 3 root root 4.0K Jun 5 18:27 ..
drwxr-xr-x 2 root root 4.0K Jun 5 15:10 include
-rw-r--r-- 1 root root 320K Jun 5 15:35 netcode.c
(base) root@WorldMap:~/netcodeServer/src/netcode# cd include/
(base) root@WorldMap:~/netcodeServer/src/netcode/include# ls -lah
total 24K
drwxr-xr-x 2 root root 4.0K Jun 5 15:10 .
drwxr-xr-x 3 root root 4.0K Jun 5 15:35 ..
-rw-r--r-- 1 root root 13K Jun 5 15:10 netcode.h
are taken respectively taken from:
netcode.h : https://github.com/mas-bandwidth/netcode/blob/main/netcode.h
netcode.c : https://github.com/mas-bandwidth/netcode/blob/main/netcode.c
Client side :
(base) raphy@raohy:~/netcodeClient$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.15...3.31)
project(NetCodeClient)
include(CMakePrintHelpers)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
# https://github.com/robinlinden/libsodium-cmake?tab=readme-ov-file#using-in-your-project
# https://www.tldrlegal.com/license/isc-license
FetchContent_Declare(Sodium
GIT_REPOSITORY https://github.com/robinlinden/libsodium-cmake.git
GIT_TAG e5b985ad0dd235d8c4307ea3a385b45e76c74c6a # HEAD, last updated at 2025-04-13
)
set(SODIUM_DISABLE_TESTS ON)
FetchContent_MakeAvailable(Sodium)
add_executable(${PROJECT_NAME}
src/netcode/netcode.c
src/client.c
)
target_include_directories(${PROJECT_NAME} PUBLIC
src/netcode/include
)
target_link_libraries (${PROJECT_NAME} PUBLIC
sodium
)
(base) raphy@raohy:~/netcodeClient/src$ ls -lah
total 20K
drwxrwxr-x 3 raphy raphy 4,0K giu 5 18:25 .
drwxrwxr-x 4 raphy raphy 4,0K giu 5 18:28 ..
-rw-rw-r-- 1 raphy raphy 5,0K giu 5 18:19 client.c
drwxrwxr-x 3 raphy raphy 4,0K giu 5 18:17 netcode
(base) raphy@raohy:~/netcodeClient/src$ ls -lah ./netcode/
total 332K
drwxrwxr-x 3 raphy raphy 4,0K giu 5 18:17 .
drwxrwxr-x 3 raphy raphy 4,0K giu 5 18:25 ..
drwxrwxr-x 2 raphy raphy 4,0K giu 5 18:17 include
-rw-rw-r-- 1 raphy raphy 320K giu 5 18:17 netcode.c
client.c : https://github.com/mas-bandwidth/netcode/blob/main/client.c
where:
NETCODE_CONST char * server_address = "aaa.aaa.a.aaa:40000";
netcode.h : https://github.com/mas-bandwidth/netcode/blob/main/netcode.h
netcode.c : https://github.com/mas-bandwidth/netcode/blob/main/netcode.c
Building and executing the Server :
[100%] Built target NetCodeServer
(base) root@WorldMap:~/netcodeServer# ./builddir/NetCodeServer
[server]
server listening on aaa.aaa.a.aaa:40000
server started with 256 client slots
Building and executing the Client I get `client connect failed. connection request timed out :
(base) raphy@raohy:~/netcodeClient$ ./builddir/NetCodeClient
[client]
client started on port 55685
client id is f09c63de9897b8a4
client connecting to server aaa.aaa.a.aaa:40000
client connect failed. connection request timed out
client disconnected
OS: Ubuntu 24.04 gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
What am I doing wrong and/or missing? How to make it work?