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

Author Topic: Complete newbie q's  (Read 5015 times)

0 Members and 1 Guest are viewing this topic.

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Complete newbie q's
« on: September 27, 2012, 04:49:26 pm »
Try not to laugh too hard.

So I'm using this code: https://github.com/SFML/SFML/wiki/SourceNetworkChatExample

So my questions are:
1. Do both ends (server and client) have to have the same program running?
2. I'm using my own public IP address in the sf::TcpSocket.connect() function. Is this alright?
3. If so, can I act as both server and client in order to test the program?
4. Can I use different computers with the same IP address in order to test the program?
5. What happens if I send a packet from the program to a random IP address and the port is open?

Thanks is advance.  ;)



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Complete newbie q's
« Reply #1 on: September 27, 2012, 04:55:35 pm »
Quote
1. Do both ends (server and client) have to have the same program running?
No, client and server only need to talk the same network protocol.

Quote
2. I'm using my own public IP address in the sf::TcpSocket.connect() function. Is this alright?
It's ok, but with the public IP your data will go through the public internet. Which means that you must configure your router so that it correctly opens and forwards the port(s) that you use.
For local tests you should rather use your private IP, or localhost (127.0.0.1).

Quote
3. If so, can I act as both server and client in order to test the program?
Sure.

Quote
4. Can I use different computers with the same IP address in order to test the program?
If you use the private IP you won't have this problem.

Quote
5. What happens if I send a packet from the program to a random IP address and the port is open?
Then the program which listens on the random IP computer will receive your data, and what happens totally depends on what this program does. But you're unlikely to find an open port on a random IP.
Laurent Gomila - SFML developer

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: Complete newbie q's
« Reply #2 on: September 27, 2012, 07:48:30 pm »
Wow! This is magic. :D

I got two computers to communicate using private IPs!

Now,

1. Would a connection using a cable LAN work the same way?
2. I use the public IP to connect to a comp outside my router, right?
3. Is this a reliable site to check if a port is open? http://www.yougetsignal.com/tools/open-ports/
4. The process (app logic) should be more or less the same no matter if using private IP or public IP?

Thank you once again!
Hero member indeed.



zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Complete newbie q's
« Reply #3 on: September 27, 2012, 08:01:55 pm »
Quote
1. Would a connection using a cable LAN work the same way?
As opposed to a wireless lan? Your code is the same regardless of a cabled lan or wireless lan.
Quote
2. I use the public IP to connect to a comp outside my router, right?
Yes.
Quote
3. Is this a reliable site to check if a port is open? http://www.yougetsignal.com/tools/open-ports/
Of your computer or a remote computer?
Quote
4. The process (app logic) should be more or less the same no matter if using private IP or public IP?
It makes no difference, your code should not matter if it is a private or public ip once you have an established connection.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: Complete newbie q's
« Reply #4 on: September 27, 2012, 08:25:03 pm »
Quote
As opposed to a wireless lan? Your code is the same regardless of a cabled lan or wireless lan.

I meant connecting two comps with Ethernet cable. :)

Quote
Of your computer or a remote computer?

My computer. Only the server needs an open port, right?

Thank you. :)



zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Complete newbie q's
« Reply #5 on: September 27, 2012, 10:15:40 pm »
Quote
I meant connecting two comps with Ethernet cable. :)
You mean plugging an ethernet cable into one computer and then plugging the other end into another computer with no router in the middle? That won't work unless you are using a crossover ethernet cable or you have a router in the middle.

And yes, with two computers properly connected your code will always work(no matter how they are connected to the network).

Quote
My computer. Only the server needs an open port, right?
Yes, only the server needs an open port. The site you posted should work fine for checking open ports. Just remember if your behind a router your need to setup port forwarding.

PS Mind giving us a hint as to what you are trying to achieve? Maybe we can just give some straightforward advice or some links.
« Last Edit: September 27, 2012, 10:18:25 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: Complete newbie q's
« Reply #6 on: September 28, 2012, 01:48:02 pm »
Quote
if your behind a router your need to setup port forwarding.

So, If I open a port in a comp, that port is opened in all comps connected to the router?
Or opening a port of a comp as in http://windows.microsoft.com/is-IS/windows7/Open-a-port-in-Windows-Firewall is different from "port forwarding"?

Quote
PS Mind giving us a hint as to what you are trying to achieve? Maybe we can just give some straightforward advice or some links.

As in now, I'm just messing around. In the future I plan to make an online rpg.

Thank you once again. :)



zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Complete newbie q's
« Reply #7 on: September 28, 2012, 02:20:05 pm »
So, If I open a port in a comp, that port is opened in all comps connected to the router?
Or opening a port of a comp as in http://windows.microsoft.com/is-IS/windows7/Open-a-port-in-Windows-Firewall is different from "port forwarding"?

Ok, I will try for the short and sweet explanation. Only a server needs to have the incoming ports opened to allow the clients to connect. On your computer (if it is the server), you need to make sure that your firewall (ie windows firewall, comodo, mcafee...) is not blocking incoming ports that your application(which is the software that makes the server) wants to use.

After that if your computer (the server) is connected through a router to your internet connection you need to open the ports your server will be using inside the router. You normally can access the router through 192.168.x.x or \\router. Then follow your documentation to setup port forwarding on your router.

And then to test your server through the internet you can have a buddy with another internet connection try to connect to your server.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: Complete newbie q's
« Reply #8 on: September 30, 2012, 03:19:16 am »
Thank you, for you time.

I have another question. :)
The example chat uses sf::Thread. Are threads speed independent of the game fps. So, for example, the "threads cycle" will run faster on a faster computer not matter if the fps is set to a specific value?
Or are threads co-dependent on the game's fps?



eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Complete newbie q's
« Reply #9 on: September 30, 2012, 07:33:58 pm »
The example chat uses sf::Thread. Are threads speed independent of the game fps. So, for example, the "threads cycle" will run faster on a faster computer not matter if the fps is set to a specific value?
Or are threads co-dependent on the game's fps?
Depends on how you limit the FPS.
If you use setFramerateLimit then only the thread that holds the window will get limited and if you set VSync then only the thread that draws will be limited.
Keep in mind threads can be completely independent applications (see here for more information).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Qix

  • Full Member
  • ***
  • Posts: 139
  • I am Qix!
    • View Profile
    • Natoga Technologies
Re: Complete newbie q's
« Reply #10 on: October 08, 2012, 01:07:50 am »
I know I'm re-iterating a lot of things people have said here, but I just wanted to throw in my own wording on a few questions.

Quote
2. I'm using my own public IP address in the sf::TcpSocket.connect() function. Is this alright?

This depends; if by public IP you mean not your LAN IP, but the one that your modem uses to connect to the internet (your WAN IP) and you are behind a router, then no simply because your computer has no knowledge of what your router's IP address is; it only knows the one it was assigned (i.e. most likely a 192.168.x.x IP address).

Quote
2. I use the public IP to connect to a comp outside my router, right?
Further, you cannot connect to your WAN IP address from inside the LAN it belongs to. Look up host files.

If you are behind a router and want to have people from outside your LAN connect to it, you must listen on a port on your local IP (usually just specify 'all' IP addresses to bind to) and then port forward with your modem and/or router. See diagram.



Quote
3. Is this a reliable site to check if a port is open? http://www.yougetsignal.com/tools/open-ports/
Any sites work. See my warning below about port scanning.

However, if they are connecting from inside the LAN, then they need to connect using the LAN IP address (i.e. 192.168.x.x).

Quote
If so, can I act as both server and client in order to test the program?

Yes, this is just fine. Keep in mind, however, that testing with a program just like Wireshark will not work. Why? Because the computer is usually smart enough to realize it's connecting to itself, thus circumventing the actual NIC card entirely (to speed things up; it's a feature, not a bug!). This means that PCAP (the underlying driver that those programs usually use) won't detect it, and your packets won't show up.

You can, however, use WPE Pro; however, most AVs detect it as a virus (it is not) and it has very limited features and feedback (it was meant for editing packets and doing hack-ish kind of things moreover than debugging applications).

Quote
4. Can I use different computers with the same IP address in order to test the program?
Two computers cannot function on the same network with the same IP address. You can configure static IPs to be the same but the router will reject one of them (whichever is the second to connect).

Quote
5. What happens if I send a packet from the program to a random IP address and the port is open?
There are several answers to this question, the most blunt and simple answer would be "nothing". The chance of finding a random port on a random IP (without port scanning, which, depending on where you live or the terms you have with your ISP is extremely illegal, ESPECIALLY if you happen to scan, say, a government IP, which is a federal offence) is extremely slim (ports range from 1-65535).

Secondly, how it handles the data has two parts; what protocol does it use (TCP/UDP; basically, will it even connect?) and what program is using the port? Network activity doesn't care what the receiving program does with it; its job is to transport something to something else. That's it. The beauty of networking is that, not only can it (obviously) transport things across long distances, but that you could have any program in any programming language send and receive data with another completely different program, so long as they know what they are talking about.

While UDP doesn't use connections, most of the time a server that receives a packet that it doesn't understand will simply ignore it. TCP servers generally accept any connect, perform some sort of authentication ("hey, how can I help you?" "Oh I am an IRC client" "Oh, you connected to a web server, I have no idea what you are talking about, goodbye"), which means it will refuse/disconnect any connections it doesn't recognize.

Quote
1. Would a connection using a cable LAN work the same way?
Quote
I meant connecting two comps with Ethernet cable.
It does; however, it's usually not as easy as you'd think. You usually have to get something called a 'crossover cable' because some of the connections need to be switched in the cable itself. A router actually takes care of this for you; direct connections do not.

Quote
So, If I open a port in a comp, that port is opened in all comps connected to the router?
Not quite. When you port forward, the router needs to know which computer to forward the data to (the router has no idea which ports are open on which computers; its job is to simply allow/refuse/direct traffic from one port to the others with IP addresses).

Usually when you port forward, it just forwards a port (heh) from the modem (WAN) IP address to a specific IP address that you supply. A lot of routers also support something called a 'virtual server' which is pretty much port forwarding, only you can specify a public port and a private port. This is useful if multiple computers are running the same software, and the software's listening port cannot be changed.

Quote
Or opening a port of a comp as in [snip .. windows firewall] is different from "port forwarding"?
Yes, simply because Windows Firewall wasn't built to route traffic like that. The firewall still has exceptions where things can get through, and often times it will refuse even outgoing connections when they are 'open'.

I do a lot of socket programming, and I've never once needed to touch the windows firewall; I usually leave it disabled because it really doesn't do anything more than prompt you if a program can connect/listen on the first program run (I'm sure some people on here will disagree, but this is purely personal experience).

The example chat uses sf::Thread. Are threads speed independent of the game fps. So, for example, the "threads cycle" will run faster on a faster computer not matter if the fps is set to a specific value?
Or are threads co-dependent on the game's fps?
Depends on how you limit the FPS.
If you use setFramerateLimit then only the thread that holds the window will get limited and if you set VSync then only the thread that draws will be limited.
Keep in mind threads can be completely independent applications (see here for more information).
Two points I'd like to extend off of eXpl0it3r: one, each process itself has one thread to begin with as it is (the 'main thread', which is actually a special thread on most systems). Secondly, while threads operate independent of FPS, they are still limited by how much time the main operating system (more specifically the 'thread scheduler') gives to the thread. That is why sleep()-like functions that pause a thread are not accurate (unless you tweak some system configuration at runtime on Windows, for example, with timeBeginPeriod [only use if you know exactly what you're doing; you shouldn't use it unless you absolutely need the most accurate timing]).

Quote
Try not to laugh too hard.
Nobody was born knowledgeable about programming. We were all clueless at some point. These are all very good questions.


Best of luck.
« Last Edit: October 08, 2012, 01:12:43 am by Qix »
~ Qix
Creator of Rippl Studio
Code: [Select]
<danharibo> iostream: I don't do enough drugs to think that's a good idea.

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: Complete newbie q's
« Reply #11 on: October 25, 2012, 04:57:37 am »
Thanks.



 

anything