Im currently learning java, and I'm developing a chat application for android (in java).
The chat application takes a username and text from the user and sends it to a server application on my computer.
The server application is written in C++ with the SFML Network library.
Here's my very simple Server (It's supposed to just write out the sent text at the moment):
#include <SFML/Network.hpp>
#include <iostream>
using namespace std;
int main()
{
sf::TcpListener listener;
if (listener.listen(4242) != sf::Socket::Done)
{
cerr<< endl << "Error: Couldn't set up TCP listener";
}
sf::TcpSocket client;
listener.accept(client);
cout << endl <<"New client connected: " << client.getRemoteAddress() << endl;
char data[100];
std::size_t received;
if (client.receive(data, 100, received) != sf::Socket::Done)
{
cerr<<endl<<"Error while receiving data";
}
else
cout << endl << "Data received: " << data;
}
Here's a snippet of my java code in which the message is being sent:
When I run both applications, the phone actually connects to my server, and the server writes "New client connected..." to the console, but I'm unable to send the "Hello World!" text. The server doesn't receive any data.
So my question is: Is it possible that the Server receives the data? And If yes, how can I achieve that and what do I have to keep in mind?