Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this questionThis is a part of c++ code to connect between client and server, I need to an android code corresponds to c++ code?
/* Create a reliable, stream socket using TCP */
if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
return ("Could not create socket!");
/* Construct the server address structure */
memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */
echoServAddr.sin_family = AF_INET; 开发者_C百科 /* Internet address family */
echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */
echoServAddr.sin_port = htons(echoServPort); /* Server port */
/* Establish the connection to the echo server */
if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
return ("Could not connect to socket!");
I'm not a code converter (at least not officially) but look into Java's Socket. See example here.
精彩评论