Hi guys, for a school project i have to use sockets to create a server, i think i managed to do it but i am supposed to use Telnet to test it an whenever i try i get a "telnet: connect to address 0.0.0.0: Connection refused" so i guess it is with the IP that i'm wrong the simplified version of my code that should still work for one connection is Spoiler Code: int main(int argc , char *argv[]) { int sock; int fd = 0; int err = 0; struct sockaddr_in sock_data; socklen_t addr_size; char *path; path = get_current_dir_name(); if (argc == 2) printf("%s", Usage); sock = socket(AF_INET , SOCK_STREAM , 0); if (sock == -1) { printf("Could not create socket"); return (84); } memset(&sock_data, 0, sizeof(struct sockaddr_in)); sock_data.sin_family = AF_INET; sock_data.sin_port = htons(5133); sock_data.sin_addr.s_addr = htonl(INADDR_ANY); printf("%s, %s, %s\n", path, sock_data.sin_addr, inet_ntoa(sock_data.sin_addr)); if (bind(sock, (const struct sockaddr *) &sock_data, sizeof(sock_data)) == -1) printf("Error with binding\n"); if (listen(sock, LISTEN_BACKLOG) == -1) printf("Error with listen"); addr_size = sizeof(struct sockaddr_in); err = accept(sock, (struct sockaddr *) &sock_data, &addr_size); while ((sock = accept(sock, NULL, NULL)) < 0) { err = 0; }; return 84; } so do you know where i went wrong?
Did you try 'localhost' instead of '0.0.0.0' ? I mean you are testing the server socket on your machine, right?
Why not 127.0.0.1? Connection refused generally means that nothing is listening on that address and port. So make sure you're connecting on port 5133 too.
i still got connection refused but thanks and yup ^^ i get the same result with 127.0.0.1 and when i try to print the adresse i get 0.0.0.0 how do i make sure that i am connecting on 5133?
yeah i'm truly an idiot Q-Q thanks man, i can't believe i spent three days re-writing my program because i forgot one stupid thing XD
No worries. While you do need to ask more questions, this experience will help you in the long run as it exposes you to all sorts of weirdness that you won't get to see if you keep getting it right.