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

Author Topic: problems with sf::TcpSocket  (Read 3838 times)

0 Members and 1 Guest are viewing this topic.

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
problems with sf::TcpSocket
« on: December 28, 2013, 08:38:59 pm »
I wrote two comments where it`s a trouble. I`ll be realy happy if u help me. I love to make fails at start of learning something.
It works if i run it on my computer, but if i run it on the computer and laptop it isn`t works..

Windows 7, Visual studio 10.

// SERVER
int main()
{

        std::cout<<"It`s start to work"<<std::endl;

sf::TcpListener listener;

listener.listen(21);

short int port = listener.getLocalPort();
std::cout<<port<<std::endl;  


sf::TcpSocket socket;
listener.accept(socket);
std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;


getch();
}



// CLIENT


int main(){
sf::TcpSocket socket;
int port, port2;


sf::Socket::Status status = socket.connect("ip", 21);   /* Is there i need to choose my ip? Or some specific
adress, becouse it doesn`t work with my ip adress : remote port show zero and no messages on the server
*/


if (status != sf::Socket::Done)
{
   std::cout<<"error";
}

else {
        std::cout<<"done"; }


port = socket.getRemotePort();
std::cout<<"Remote "<<port<<std::endl;   /* here remote port show zero (i told about it) */
port2 = socket.getLocalPort();
std::cout<<"Local "<<port2<<std::endl;


getch();
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10838
    • View Profile
    • development blog
    • Email
Re: problems with sf::TcpSocket
« Reply #1 on: December 29, 2013, 12:37:20 am »
If you want help, you need to clearly state what you're trying to do, what you'd expect to happen and what actually happens/what problems there are. Posting some code with some even more vague comments don't help us understand your problem. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Omega

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: problems with sf::TcpSocket
« Reply #2 on: December 29, 2013, 02:24:53 am »

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: problems with sf::TcpSocket
« Reply #3 on: December 29, 2013, 01:25:28 pm »
There are two programms (server and client) that recived information from each other. when server(at first computer) and client (at another computer)active they must send some information. But connection always fail. Client says remote adress 0.0.0.0  and remote port = 0. i think there is trouble in adress.
So the question is : what ip i must write? my IPv4 is 81.25.53.137 (that i found in the internet) (or maybe local ip that i found  by cmd in windows /netstat) or something another?
Also it doesnt work with my ip (IPv4), but if i run server and client on the same computer with my local  ip, it works. I need working at another computers.
« Last Edit: December 29, 2013, 05:26:29 pm by Salmon_Yo »

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: problems with sf::TcpSocket
« Reply #4 on: December 29, 2013, 05:28:29 pm »
Go to cmd and type ipconfig or call system("ipconfig") in your program.
Then it will show you the IPv4 address. Use that address.

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: problems with sf::TcpSocket
« Reply #5 on: December 29, 2013, 06:01:16 pm »
Go to cmd and type ipconfig or call system("ipconfig") in your program.
Then it will show you the IPv4 address. Use that address.

It`s show me two IPv4 starts with 10.40.*.* it`s local network, isnt it? It works on my computer, but if separate it on different computers it`s show again 0.0.0.0 (and remote port = 0)

Omega

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: problems with sf::TcpSocket
« Reply #6 on: December 29, 2013, 06:39:10 pm »
So the question is : what ip i must write?

You use whatever IP address the host (server side) is at. If the IP address is 81.25.53.137, then on the client side you use that. If it's something else, then you use that. However, you just cannot use some arbitrary IP address. That is not how networking works.

Also, use a port other than 21 (FTP).

Salmon_Yo

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • Email
Re: problems with sf::TcpSocket
« Reply #7 on: December 29, 2013, 07:14:48 pm »
So the question is : what ip i must write?

You use whatever IP address the host (server side) is at. If the IP address is 81.25.53.137, then on the client side you use that. If it's something else, then you use that. However, you just cannot use some arbitrary IP address. That is not how networking works.

Also, use a port other than 21 (FTP).
But it isnt work with this ip adress and I dont know why. If I ask program to show remote ip after connection fail, it s show me 0.0.0.0 but I told him "search 812553137 adress. I m god here." It doesnt like me.
I chose another port (15 and 46644) finaly - no changes.
« Last Edit: December 29, 2013, 07:17:46 pm by Salmon_Yo »

Omega

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: problems with sf::TcpSocket
« Reply #8 on: December 29, 2013, 10:39:06 pm »
I'll link you to this one more time: https://github.com/SFML/SFML/wiki/FAQ#i-cant-connect-to-the-other-computer-over-the-internet

Check your firewall settings, router settings, etc., etc. Since you are able to make your server and client connect via localhost, your connection issues are not SFML related.