Advertisement

How is a real-time server port "find" known to client code

Started by March 02, 2017 11:39 AM
51 comments, last by hplus0603 7 years, 8 months ago

Which box on your network publishes the public IP?

To check my public IP i go to whatIsMyIP.org. Its be dynamic anyway because it changes kinda every 2/3 days or so. Only the internal IP is on the router

When you connect to public-IP port 80, you are connecting to whatever is listening on that public IP address on port 80

my b, level zero on this :(

If you open up a web browser, and type in http://public-ip:80/ what page does it open?

It says "This site cannot be reached"

However, the good news is that your public IP likely has a port forwarding function. So, set up port forwarding from port 52059 on your router, to port 52059 on your PC. Then try to connect to (public-IP, 52059) from the Android. Chances are, this will reach the router, and the router will port forward to the PC.

Many thanks, I will have to check out port forwarding procedure for my router. I hope this really works

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

To check my public IP i go to whatIsMyIP.org. Its be dynamic anyway because it changes kinda every 2/3 days or so. Only the internal IP is on the router

That doesn't answer my question. My question is: The public IP you use, what particular piece of hardware actually has that address? If you have a standard home network for US households, it's probably your WiFi router, but it could be a bunch of different things -- a cable modem, an actual computer, a managed switch, etc.

If it says "this site cannot be opened," then I'm surprised that you wouldn't get a "connection refused" error/exception from the Android code that tries to connect to that address. Except, perhaps, if the Android sees your network from the outside, and your PC sees the network from the inside, and your router doesn't like serving the outside IP address to inside hosts (what's known as "hairpin NAT.")

I think that you really need to ready up on how IP networking works, and then on how the different pieces in your home network work together, before you can make more progress on your program. An excellent book about IP networking in general is "TCP/IP illustrated" by Stevens and Fall (second edition.) I highly recommend reading and understanding it, or something like it, as the necessary foundation of actually learning robust network programming!

enum Bool { True, False, FileNotFound };
Advertisement

Deploy your server to a hosted solution such as AWS EC2, Azure or Digital Ocean. Avoid port forwarding and all that silliness on your home network potentially exposing you and your family to intrusion. A $5/month server is usually more than sufficient for proof of concept and you can even pay by the hour if that seems overly expensive.

That being said definitely read up on some networking like hplus said. At worst you will understand why your solution may not be working and you will be able to share your perspectives here on gamedev.

Evillive2

Forwarding one port is not exactly a security risk. Trying to learn how to use EC2 when still fuzzy on networking basics is a good way to waste 3 months of your time.

Forwarding one port is not exactly a security risk. Trying to learn how to use EC2 when still fuzzy on networking basics is a good way to waste 3 months of your time.

Yeah, AWS is the hardest of the common virtual hosting providers :-) (They have the most features, though. And some of the highest prices!)

If you're good with the Linux, a VM from Linode or Digital Ocean or whatever is very easy to get going with. Also, Amazon Lightsail makes the simple case easier.

If you need Windows, your best bet for virtual hosting is Microsoft Azure, although some of the other vendors also have Windows-based options. Check

or

enum Bool { True, False, FileNotFound };

Finally client server communication (just simple one way client-->server comm) solved clap.gif

Many thanks everyone for little bits of help here and there!

Below is what caused the block - Just in case extreme Noobs like me come around here. Veterans and averagely experienced network programmer will find this very boring. So the fix stuff below is mainly for beginners who could find themselves stuck like I was

Apart from wrongly using '0' as port number and also wrongly closing sock and servSock within the while loop, it turns out that the code I posted in the Original Post was correct. The problem was that i was turning off the wrong firewall. There were other of firewalls I wasn't aware of. - both on windows 10 and on my Android phone - maybe rightly so, otherwise these devices would be heavily vulnerable to attacks. There was also 'port-forwarding' that I also wasn't aware of until someone suggested it.

One big problem I had (and noobs like me might have) was that every time I mentioned that my computer's firewall was turned off, I was always referring to windows defender. But socket programming can run successfully with windows defender turned ON

EDIT @[member='Kylotan'], is right! I just tested again, only steps 1 and 4 are required for connection, i got muddled up with unnecessary steps 2, 3, & 5 while 'pressing every button' to fix the issue

Steps that fixed the connection problem (EDIT: With 5 steps reduced to 2 ... its not so convoluted after all. But both are still essential and step 4 - particularly- was impossible to find anywhere on the internet )

1. Port forwarding: Though slight variation between routers/ISP the principle is the same, you can watch the details here

2. Enable nearby devices to share media files via wifi on your device. On my phone its settings>>connection>>nearby devices

3. If on windows 10, go to control panel>>systems and security>>windows firewall>>allow an app or feature through windows firewall, scroll down and check the box for "wireless portable devices" and (if not already checked) "Paid wifi and mobile"

4. if on windows 10, go to control panel>>systems and security>>windows firewall

click on "Advanced settings" (on the left)

on the panel that shows up, scroll down and click on "inbound rules"

on the right of the main panel (not the panel itself), click on "New rules"

another panel shows up. Here the default check is "program". click on port. And start to enter details as it is on your "port-forwarding" details. click "next" ... and after the last entry you click "finish"

5. finally briefly change your windows network settings from private to public, then private again. At this point a dialog would pop on your mobile device requesting if you want to allow "DAFUPnP" , click ok or yes.

Finally you are ready to go - run server and client code.

With this foundation of a simple application sorted, now the journey to the deeper ends of client-server programming can begin

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

Advertisement

Thanks for following up with what worked for you!

And, yes, Windows Defender is more of an anti-malware and less of a firewall, as you found out :-)

Glad it's working for you now. Good luck on your project!

enum Bool { True, False, FileNotFound };

Some few questions remain, some of which i'm sure would end up being stupid questions, but I don't know how to not ask stupid questions at this stage that I'm still very much a novice. so bear with me...

Few questions:

since TCP/IP is widely regarded as Not secure, why is it widely still widely in use?

why doesn't my router/ISP give me a more secure HTTPS option during port forwarding?

and crucially I am about to purchase "TCP/IP illustrated" by Stevens and Fall, but why is this recommended book if the protocol is not a secure protocol?

whats a recommended https client server resource/book?

Ultimately, I would want users of my android app to be able to send data to my server, my code (at the server end) works on these data and sends results back to the individual client user's handset, in a simple a-b-c description (just saying so I don't get lost), whats the best setup (secured) process i should have?

And further reading recommended?

many thanks

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

Few questions:
since TCP/IP is widely regarded as Not secure, why is it widely still widely in use?


It's not widely regarded as insecure. Where did you hear that?

TCP/IP is pretty much security agnostic. It provides a way to form a certain kind of connection across the internet, nothing more. Security is layered on top. See below...

why doesn't my router/ISP give me a more secure HTTPS option during port forwarding?


Because your router doesn't know or care (much) about HTTP or HTTPS. These are called 'application' layers, and they sit on top of TCP. It's the responsibilty of the processes at each end of the connection to set these protocols up. Scan this article for a brief overview: https://en.wikipedia.org/wiki/Protocol_stack
HTTPS is a secure version of HTTP. You could reasonably ask "why is HTTP widely in use when it's insecure" and the answers are:

  • it's easier to configure
  • it's easier to test (e.g. with telnet)
  • historically, HTTPS required that you pay a 3rd party to verify your server's identity

and crucially I am about to purchase [background=#fafbfc] [/background]

"TCP/IP illustrated" by Stevens and Fall, but why is this recommended book if the protocol is not a secure protocol?
whats a recommended https client server resource/book?


If you just want to make applications, you don't need to buy a networking book. There's certainly no need for a book merely on HTTPS because the protocol is fairly simple. Once you have the connection set up then it's basically just like HTTP. What follows that will depend on your application's needs.

Ultimately, I would want users of my android app to be able to send data to my server, my code (at the server end) works on these data and sends results back to the individual client user's handset, in a simple a-b-c description (just saying so I don't get lost), whats the best setup (secured) process i should have?

A HTTPS connection is probably fine for your needs.

P.S. I'm pretty sure you don't need steps 2 and 3 in your security checklist above. I'd also be surprised if you needed step 5. But who knows. Step 1 is essential for the data to get from the router to your PC. Step 4 is essential for the data to get from your PC to the server process.

many thanks for post, its very helpful.

It's not widely regarded as insecure. Where did you hear that?

My bad, I should have included links with the post. Here is the link

http://www.linuxsecurity.com/resource_files/documentation/tcpip-security.html

pretty much the first paragraph says all, from your reply though, i take it I must have misunderstood the article

can't help being grumpy...

Just need to let some steam out, so my head doesn't explode...

This topic is closed to new replies.

Advertisement