I’m writing C++ network server prototype on linux. I have obtained socket file descriptor, bound it to 127.0.0.1 on port 6666, marked socket with listen and called accept. Program runs until accept without eny error, then waits.
Still there is no record about my socket in nestat --all.
I have tried command telnet 127.0.0.1 6666 and got connection refused, but my server was still running.
I don’t think that it’s caused by firewall, because example found on internet works. I think there might be some mistake in error handeling, I’m not very familiar with C++ yet.
Here is my source code on pastebin.
Thank you for your time and effort! 🙂
Note that your
incoming_addris declared as a pointer, thus yoursizeofis returning the pointer’s size. Try withsizeof(struct sockaddr_storage).getAddressshould receive aconst char *addressrather thanconst char address. You really want to pass the whole address instead of only the 1st character. This also requires you to remove the&fromaddressininet_addr(&address), and call the function asgetAddress(addr, SERVER_PORT).