-3

This 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;             /* 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!");
RivieraKid
  • 5,923
  • 4
  • 38
  • 47
user875264
  • 55
  • 2

1 Answers1

1

I'm not a code converter (at least not officially) but look into Java's Socket. See example here.

MByD
  • 135,866
  • 28
  • 264
  • 277