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

Author Topic: TCP Socket won't block. Am I missing something  (Read 7854 times)

0 Members and 1 Guest are viewing this topic.

average

  • Newbie
  • *
  • Posts: 2
    • View Profile
TCP Socket won't block. Am I missing something
« on: January 04, 2021, 02:27:48 am »
Basically title. My UDP sockets block fine but my TCP Sockets wont block. I'm sure they can block but am I wrong?  I've tried using a selector but have the same results.

Client Side:
        sf::TcpSocket serverSocket;
        serverSocket.setBlocking(true);
        sf::Socket::Status status = serverSocket.connect(serverIP, 5645);


        if(serverSocket.receive(serverData) != sf::Socket::Done)
        {
                //error
        }
 


Server Side:
sf::SocketSelector selector;
        sf::TcpListener listenerSocket;
        if (listenerSocket.listen(5645) != sf::Socket::Done)
        {
                std::cout << "Failed to bind listener socket\n";
        }
        selector.add(listenerSocket);
if (selector.wait(portCheckTime))
                {
                        // Test the listener
                        if (selector.isReady(listenerSocket))
                        {

                                sf::TcpSocket client;

                                if (listenerSocket.accept(client) == sf::Socket::Done)
                                {

                                        std::cout << "A client has joined\n";

                                }
if (client.send(serverData) == sf::Socket::Done)
                                {
                               
                                        if (iteration == 1)
                                        {
                                                iteration = 2;
                                        }
                                        else if (iteration == 2)
                                        {
                                                iteration = 1;
                                        }
                                        socket++;
                                }
 

Kvaz1r

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: TCP Socket won't block. Am I missing something
« Reply #1 on: January 04, 2021, 11:09:24 pm »
All sockets are blocking by default...can you provide minimal example for reproducing the behaviour?