Hi everyone, I am writing socket programming in c in Linux. I wrote client and sever programs. But when I run it, server is ok. But client showed that connection refused error. Why is it so?
My client code is
so in my server program, I should include until accept the connection right? Currently my client program gave me the error "Address family not supported by protocol". :(
You should specify the protocol in: socket(AF_INET, SOCK_STREAM,0)
The BSD socket library attepts to fill in the protocol for you if you specify 0. But WinSock won't for example. So you may as well just say what it is. Asl it happens, PF_INET has the same value as AF_INET, but socket() really takes PF_INET, so you should use that. It should be: socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)
It's always best to zero out the address structures before using them. You did that, but comment out the code.
You shouldn't use htol on INADDR_ANY. So this is wrong. serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
I can't really see anything else that's wrong other than the missing accept() lopp/client processing.
When I wrote a c# server program in window and c client program in Linux, when I run client program it showed connection refused again. :( Between 2 computers, I used crossover cable.