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?
Also, as the FAQ states: 9. When all else fails, you can always come to the SFML forum and ask for help there.
;)
Question is: Did you go through 1. - 8. first, because you never told us what you've tried so far and instead just provided the code in hope we'd fix things for you. ;)
Install Wireshark on your server and see what you actually receive.
Additionally just comparing your code to what the official tutorials teach, I don't see you checking whether the connection was accepted properly:
sf::TcpSocket client;
listener.accept(client);
vs
sf::TcpSocket client;
if (listener.accept(client) != sf::Socket::Done)