c - Bind: Address Already in Use -
I'm trying to run my server program but I get this error:
Error on binding: Address is already in use
int main (int argc, char * argv []) {if (argc & lt; 6) {printf ("use: string explorer & Lt; filename & gt; & lt; stringLength & gt; & lt; discovered & gt; & lt; n earrings & gt; & lt; nThreads & gt; & lt; blockux & gt; \ n "); Exit (0); } Char * fileName = argv [1]; Int stringLen = atoi (argv [2]); Int searchLen = atoi (argv [3]); N Child = Atoy (argv [4]); If (nChildren == 0) nChildren = 1; Int nThreads = Atoi (argv [5]); Int blockosis = Atoian (argv [6]); Int childNo = 0; // opens new socket int scaffold; Sockfd = Socket (AF_INET, SOCK_STREAM, 0); If (Sokfad & lt; 0) {mirror ("error opening socket"); Exit (0); } Int Newsfoody, Portano, Cleine; Struct sockaddr_in serv_addr, cli_addr; Int n; Portano = 5000; Serv_addr.sin_family = AF_INET; Serv_addr.sin_addr.s_addr = INADDR_ANY; Serv_addr.sin_port = htons (portno); Int opt = 1; SetOp (1, SOL_SOCKET, SO_REUSEADDR, and Opt, Size (opt)); If (bind (Sokfad, (Structured Socied *) and Serv-ADD, Size (all_ADDR)) <0 {mirror ("on binding error \ n"); Exit (1); }
setocop (1, SOL_SOCKET, SO_REUSEADDR, and opt, sizeof Alternative));
The first argument should be sockfd and not '1'
Comments
Post a Comment