c++ - connect to host in C -


i have connect host , port. port const, host variable should input shell. i've got error.

int main(int argc, char ** argv) {     if (argc<2){         printf("need more arguments\n");         return 1;     }     int sock;     if((sock = socket(af_inet, sock_stream, 0)) < 0){         perror("socket creating error");         return 1;     }      struct sockaddr_in addr;     addr.sin_family = af_inet;     addr.sin_port = htons(22222);     addr.sin_addr.s_addr = argv[1];    // try conect host ... } 

you can't assign host s_addr that. need convert string host name/ip number correct format s_addr

if you're posix, @ getaddrinfo() otherwise can use things inet_addr(), gethostbyname(), gethostbyaddr() , on. key being, need make conversion.

i suggest google example client/server code... there's ton of it. including here on so.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -