SFML community forums

Help => Network => Topic started by: Salmon_Yo on December 28, 2013, 08:38:59 pm

Title: problems with sf::TcpSocket
Post by: Salmon_Yo 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();
}
Title: Re: problems with sf::TcpSocket
Post by: eXpl0it3r 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. ;)
Title: Re: problems with sf::TcpSocket
Post by: Omega on December 29, 2013, 02:24:53 am
Don't use port 21 unless it's for FTP (http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml).

Try reading this (https://github.com/SFML/SFML/wiki/FAQ#i-cant-connect-to-the-other-computer-over-the-internet) and see if it solves your problem.
Title: Re: problems with sf::TcpSocket
Post by: Salmon_Yo 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.
Title: Re: problems with sf::TcpSocket
Post by: iride 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.
Title: Re: problems with sf::TcpSocket
Post by: Salmon_Yo 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)
Title: Re: problems with sf::TcpSocket
Post by: Omega 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).
Title: Re: problems with sf::TcpSocket
Post by: Salmon_Yo 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.
Title: Re: problems with sf::TcpSocket
Post by: Omega 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.