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

Author Topic: send() always != socket.Done  (Read 3488 times)

0 Members and 1 Guest are viewing this topic.

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
send() always != socket.Done
« on: October 15, 2012, 02:15:10 am »
Hi, i just try to run the code found in the doc for TCP server/client.

 ----- The client -----

 // Create a socket and connect it to 192.168.1.50 on port 55001
 sf::TcpSocket socket;
 socket.connect("myOnlineIP", 55001);

 // Send a message to the connected host
 std::string message = "Hi, I am a client";
 socket.send(message.c_str(), message.size() + 1);

 // Receive an answer from the server
 char buffer[1024];
 std::size_t received = 0;
 socket.receive(buffer, sizeof(buffer), received);
 std::cout << "The server said: " << buffer << std::endl;

 // ----- The server -----

 // Create a listener to wait for incoming connections on port 55001
 sf::TcpListener listener;
 listener.listen(55001);

 // Wait for a connection
 sf::TcpSocket socket;
 listener.accept(socket);
 std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;

 // Receive a message from the client
 char buffer[1024];
 std::size_t received = 0;
 socket.receive(buffer, sizeof(buffer), received);
 std::cout << "The client said: " << buffer << std::endl;

 // Send an answer
 std::string message = "Welcome, client";
 socket.send(message.c_str(), message.size() + 1);





And now my question: I don't understand why the send function failed all time. ( != sock.done ).
But if I use loopback IP the program work fine.

I tried to disable antivirus,firewall and router tcp socket check but the issue still continue.


Any1 got suggestion for solve this problem ? :)


Info: ( lastest sfml 2 version, windows 7 )

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: send() always != socket.Done
« Reply #1 on: October 15, 2012, 08:04:54 am »
Is it "send" or "connect" that fails. How do you know that it doesn't return sf::Socket::Done, your program doesn't check anything?
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: send() always != socket.Done
« Reply #2 on: October 15, 2012, 09:27:43 am »
My program check that ! :) ( I copied the code from the doc for lazyness )

btw connect fail too !

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: send() always != socket.Done
« Reply #3 on: October 15, 2012, 09:29:34 am »
Can you show your real code? If possible, showing a complete and minimal version of it that reproduces the problem would be nice :)
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: send() always != socket.Done
« Reply #4 on: October 15, 2012, 10:17:35 am »
the check that  i did is on send function--> if ( send != done ) { //error }

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: send() always != socket.Done
« Reply #5 on: October 16, 2012, 01:42:04 am »
I really don understand where is the problem, i tried all together disabled ( antivirus-windowsfirewall-routercheckOnPort ) but still not working !

And again only on 127.0.0.X work.

I tried to make listener which listen on anyport, i tried all i think.

Mmm.. btw, how can I see if connect fail function fail ? I'm concentrate on send fail but surely there is an issue on a connect function too.

:(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: send() always != socket.Done
« Reply #6 on: October 16, 2012, 08:07:53 am »
Did you actually read my last post?
Quote
Can you show your real code? If possible, showing a complete and minimal version of it that reproduces the problem would be nice

Quote
btw, how can I see if connect fail function fail ?
The same as for send... Don't hesitate to look at the code examples and the online API doc.
Laurent Gomila - SFML developer

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: send() always != socket.Done
« Reply #7 on: October 16, 2012, 02:51:29 pm »
sorry !  ;D


client part that not connect:

        if ( socket.connect(sf::IpAddress::getPublicAddress(), 55001) != sf::Socket::Done )
// i tried with writing my IP public address by my hands too..
        {
                std::cout<<"Error\n";
                return 1;
        }

server:

         sf::TcpListener listener;
         listener.listen(listener.AnyPort); // i tried 55001 too

         // Wait for a connection
         sf::TcpSocket socket;
         listener.accept(socket);
         std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;


The client fail and server dont do anything like the sock never arrive.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: send() always != socket.Done
« Reply #8 on: October 16, 2012, 03:11:23 pm »
Seriously, what's complicated to understand with the words complete and minimal? :(

http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368

By the way, you're using your public IP and therefore you need to setup your router correctly. You should try with your local IP or localhost -- I would have told you earlier if your first message didn't wrongly said that you used your local IP.

It's really annoying when you try to help someone but only get vague, incomplete or even incorrect information. If you want to get efficient and relevant replies, please focus on providing complete and correct information about your code and your problem.
« Last Edit: October 16, 2012, 03:15:14 pm by Laurent »
Laurent Gomila - SFML developer

 

anything