0
votes

How can I send packet from android to SFML tcp server which is awaiting for int8 variable.

Server side:

  sf:Int8 liczbunia;
    listener.listen(55555);
    listener.accept(socket);
    cout << "connected";
    sf::sleep(sf::milliseconds(500));
    socket.receive( paket );
    paket >>  liczba;

I tried this code for client side:

        Socket socketClient = new Socket("192.168.0.100",55555); 
        PrintWriter(socketClient.getOutputStream(),true);
        DataOutputStream dout = new DataOutputStream(socketClient.getOutputStream());
        dout.writeInt(9);
        dout.flush();

Although the client connects to server, server doesn't receive the packet. What is the best way to send packets from android?

1

1 Answers

0
votes

From the tutorial on sf::Packet:

Packets solve the "message boundaries" problem, which means that when you send a packet on a TCP socket, you receive the exact same packet on the other end, it cannot contain less bytes, or bytes from the next packet that you send. However, it has a slight drawback: To preserve message boundaries, sf::Packet has to send some extra bytes along with your data, which implies that you can only receive them with a sf::Packet if you want them to be properly decoded. Simply put, you can't send an SFML packet to a non-SFML packet recipient, it has to use an SFML packet for receiving too. Note that this applies to TCP only, UDP is fine since the protocol itself preserves message boundaries.

Solution: read raw data from the socket.