I'm programming a Java server and a C++ client with the purpose of send Strings between them. But I am having so much problems with C++...
On my server, I create the server socket that listens on. After connection I expect a client message with:
entrada = new DataInputStream(socketCliente1.getInputStream());
mensajeRecibido=entrada.readUTF();
In my client I create the socket and connect as follows:
SOCKET ConnectSocket = INVALID_SOCKET;
WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
struct addrinfo *result = NULL, *ptr = NULL, hints;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
iResult = getaddrinfo("192.168.0.17", DEFAULT_PORT, &hints, &result);
ptr = result;
ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);
iResult = connect(ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
freeaddrinfo(result);
The problem comes here ... How do I send the String to the Java server?
And if I write in the Java server as:
output = new DataOutputStream (socketCliente1.getOutputStream ());
salida.writeUTF ("Hello");
How could receive with my C++ client?
If it's possible I would like not to touch the code in Java, because it has to work with Java clients too (which I have not had any problems to implement).
I don't have so much idea about C, so please, if it's possible tell me details like the libraries to use in the answer.