Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - shawnku

Pages: [1]
1
I am trying to setup a simple client/server where the client sends data (a string) over a TCP socket to the server and the server displays it. The first time I do this it works perfect, the server receives the data from the client and displays the string as it should . However, even though I have my .receive in a loop always awaiting new data it seems to not update the sentence variable I extract from it . I have checked and the client is definitely sending new information, and the servers seems to be receiving the packet but it is not updating.

Here is my server code:

int main() {
    std::string sentence;
    sf::Packet packet;
    sf::TcpListener listener;
    sf::TcpSocket client;
   

    // bind the listener to a port
    if (listener.listen(53000) != sf::Socket::Done)
    {
        cout << "error listening";
    }

    // accept a new connection

    if (listener.accept(client) == sf::Socket::Done)
    {
        cout << "accepted and working :";
    }

    while (1) {
        client.receive(packet);
        packet >> sentence;
        cout << sentence;
    }
cin.get();

}

and my client sending the information:

sf::TcpSocket socket;

sf::Packet packet;
std::string sentence;



 if (...) {

                            packet << sentence;
                            socket.send(packet);
                            cout << sentence;

                        }

whenever i run
socket.Error()
on my client it reads 0 -- no errors, however if i do the same on my server when it receives, it gives me "4" meaning unexpected error

Pages: [1]
anything