QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: awkutchins on May 29, 2020, 11:50:55 am
-
Hello reader,
I am trying to get into networking and am starting simple by just trying to connect two programs on two different computers (my pc and a rpi). The rpi has this code:
And my PC has:
port = 8080
counter = 0
'port = port + 1
counter = counter + 1
With the rpi (host) program running (and the _OPENCLIENT address comes directly from result$), I try to run the client program. It tries to connect to the port 100 times but it still comes back with clientHandle& = 0.
My question is are there any settings in my pc I have to adjust in order to connect? What else might give the _OPENCLIENT trouble connecting?
Thank you
-
until someone comes to assist you, perhaps this info on connecting a windows PC with the PI might give you some ideas https://www.circuitbasics.com/how-to-connect-to-a-raspberry-pi-directly-with-an-ethernet-cable/
-
Hey Jack!
I am planning to connect a few computers to the pi at the same time on different local networks so I'm not sure if that is the best solution. I guess I can connect the two when I'm coding and testing locally but switch to wifi when the server is up and running (but at that rate I should just stick with wifi right?)
I appreciate it tho!
-
I'm not too sure but:
1. rpi and computer might not be connecting
2. I feel like this would be spamming OPENCLIENT... I think you should only connect the client once and use GET...
-
Even if _openclient returns zero? I would assume something other than qb64 is wrong I just don't know how to narrow down the problem
-
127.0.0.1 is the localhost address; connections addressed to it do not leave the computer.
You will need to replace that with the Pi's address as given by `ip addr` for the wifi interface.
-
127.0.0.1 is the localhost address; connections addressed to it do not leave the computer.
You will need to replace that with the Pi's address as given by `ip addr` for the wifi interface.
And make certain ports are open, firewalls aren't blocking anything, and all that good junk as well...
-
So I looked around on the interweb and such and did a few things:
1. I typed "ip addr" and found the line inet 192.168.1.153/24 brd 192.168.1.255, and I assume the ip I use is the 192.168.1.153?
2. I went into my router settings and allowed port range forwarding for 52030-53030 to go to the above ip address.
3. I found my ipv6 address for the pi as fe80::b3e7:3018:6543:17a2/64 and I assume the address is everything before the /64?
4. I added that address into the firewall settings for my router to allow the above ports
5. I installed ufw on the rpi and ran "sudo ufw allow 53020"
6. I changed the port value in both programs to reflect the new port (and changed the IP address on the client side to the ipv4)
Still I can't get the client to connect. What other processes/hurdles need to be done that might stop this from working?
-
I have not done anything for my pc (client). Would I have to open the port on it too?
-
1. I typed "ip addr" and found the line inet 192.168.1.153/24 brd 192.168.1.255, and I assume the ip I use is the 192.168.1.153?
Yes.
I found my ipv6 address for the pi as fe80::b3e7:3018:6543:17a2/64 and I assume the address is everything before the /64?
IPv6 addresses beginning with fe80 are a special link-local address that Linux always assigns. "Real" addresses begin with a 2. There's no need to bother with anything IPv6 related here.
went into my router settings and allowed port range forwarding for 52030-53030 to go to the above ip address.
You're not connecting from the outside internet, so port forwarding is neither applicable nor relevant.
Your server code should be calling _OPENCONNECTION repeatedly to accept new incoming connections. _CONNECTED simply tests whether a read or write on an existing connection failed or not.
See https://www.qb64.org/forum/index.php?topic=2378.0 for the full details of what the commands do. I'm sure there's also demos floating around that someone will post a link to as well.
-
Would it be relevant if I were trying to connect from the outside internet? I'm not currently but I plan to expand it to have my three friends' computers (and mine) connected all on different networks.
I updated my server code to:
PRINT "Connecting to port..." PRINT "Host name: "; hostName$
message$ = "Hello World"
LOCATE 5, 1:
PRINT "ClientHandle from _openconnection: "; clientHandle&
PUT clientHandle&
, , message$
And my client code to:
clientHandle&
= _OPENCLIENT("TCP/IP:53020:192.168.1.153")
I am getting TCP/IP:53020:127.0.0.1 as hostName$. I'm wondering if the _OPENHOST isn't working properly if it's not saying the actual IP
-
Ok so an update:
I found a nice demo in another forum post here: https://www.qb64.org/forum/index.php?topic=1389.msg105754#msg105754
I copied the code into to qb64 programs on my pc and it worked beautifully.
I then moved the host program to my raspberry pi and changed the ip address on the client program (I tried a few) and still the same problem.
I then tried to see if I could get both programs to on the pi and it can't connect. So I think it might be something with the Pi not being able to listen to a port properly or a missing library or something. I'm not too sure where to go from here tho.
After work I'm going to try to run the client program on a different pc and the host on my pc to see if I can get a connection on different devices period.
If anyone has any ideas or places for me to look I will be so grateful.