Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Chat with Me -- HOST
#1
Now, as I mentioned in the topic Come chat with me! (qb64phoenix.com), I told you guys I was going to share the HOST part of the program which we were all using to play around and chat with yesterday -- and try to highlight the steps necessary to get it to run properly for everyone.

First, let's start with the code.  We'll begin with the HOST version of my Mini Messenger (qb64phoenix.com):

Code: (Select All)
DIM SHARED Users(1 TO 1000) ' array to hold other client info
DIM SHARED NumClients
DIM SHARED out$


PRINT "[Steve's Mini Messenger]"
host = _OPENHOST("TCP/IP:7319") ' no host found, so begin new host
IF host THEN
    PRINT "[Beginning new host chat session!]"
    NumClients = 0
    client = _OPENCLIENT("TCP/IP:7319:localhost")
    IF client = 0 THEN PRINT "ERROR: could not attach host's personal client to host!"
    INPUT "Enter your name:", myname$
    'PRINT #client, myname$ + " connected!"
    PRINT "[Chat session active!]"
ELSE
    PRINT "ERROR: Could not begin new host!"
END IF ' host


DO ' host main loop
    newclient = _OPENCONNECTION(host) ' receive any new connection
    IF newclient THEN
        NumClients = NumClients + 1
        Users(NumClients) = newclient
        PRINT "Welcome to Steve's Mini Messenger!"
    END IF
    FOR i = 1 TO NumClients
        GetMessage Users(i) 'check all clients for a message
        IF out$ <> "" THEN
            l = LEN(out$)
            FOR j = 1 TO NumClients ' distribute incoming messages to all clients
                PUT #Users(j), , l
                PUT #Users(j), , out$
            NEXT
        END IF
    NEXT i

    SendMessage myname$, mymessage$, client
    _LIMIT 30
LOOP


SUB GetMessage (client) ' get & display any new message
    GET #client, , l
    IF l > 0 THEN
        out$ = SPACE$(l)
        GET #client, , out$
        VIEW PRINT 1 TO 20
        LOCATE 20, 1
        PRINT out$
        VIEW PRINT 1 TO 24
    ELSE
        out$ = ""
    END IF
END SUB

SUB SendMessage (myname$, mymessage$, client) ' simple input handler
    k$ = INKEY$
    IF LEN(k$) THEN
        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
            mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        ELSE
            IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$
        END IF
    END IF
    VIEW PRINT 1 TO 24
    LOCATE 22, 1: PRINT SPACE$(80); ' erase previous message displayed
    LOCATE 22, 1: PRINT myname$ + ": "; mymessage$;
    IF k$ = CHR$(13) THEN ' [Enter] sends the message
        IF mymessage$ = "" THEN SYSTEM ' [Enter] with no message ends program
        mymessage$ = myname$ + ":" + mymessage$
        l = LEN(mymessage$)
        PUT #client, , l
        PUT #client, , mymessage$
        mymessage$ = ""
    END IF
    IF k$ = CHR$(27) THEN SYSTEM ' [Esc] key ends program
END SUB[color=#cccccc][font=Monaco, Consolas, Courier, monospace][/font][/color]

Now, I tried to keep this as simple as I possibly could -- without any bells or whistles to complicate the viewing and understanding of the basic process we're using here -- so don't think this is anything fancy at all.  All this basically does is show how to set up a host connection, accept users trying to connect to that connection, and then transfer information back and forth between the two.

It's a demo to showcase the very bare bones of the TCP/IP stuff, and nothing more, so keep that in mind as we go along and talk about things.  Wink

First change needed to swap this over from LOCALHOST to world wide web hosting involves...   dum dum de dum....   Opening a  browser tab and going to What Is My IP? Shows Your Public IP Address - IPv4 - IPv6.  If you're using a VPN or such to protect your IP, you may be able to get by with using it, or you may not.   That all depends on your VPN's safety protocols.  If it just forwards anything that comes its way back your way, you're fine.  If it wants you to open ports and such as that and only forward certain things, then you're screwed unless you jump through their hoops and allow the transfer.  

My advice here:  Use your actual web address.  172.83.131.239 happens to be my permanent little home on the web.  From time to time, I tend to host my own website, and I need a static IP so I can always connect to it when it's up and going.  Most folks have a dynamic IP, which is assigned to them randomly every time they connect to the internet (it costs extra $$ each month for a static IP), so you'll need to update your chat program with the current IP with each reboot of your computer.

Once you've gotten your IP address, you can now go into the code above and make the drastic change from local to www connections:

Code: (Select All)
    client = _OpenClient("TCP/IP:7319:localhost")

Change the line above to where it now has your IP address, rather than "localhost".

Code: (Select All)
    client = _OpenClient("TCP/IP:7319:172.83.131.239")

^That's what it'll look like for me.  For you, the same, except with a different IP address in there.  Wink

And that's basically the ONLY TCP/IP requirement that QB64-PE makes you have to change to make it work and communicate across the net!



And chances are, if some of you try to make that work, it's not going to work for you.  In fact, I'd bet against it.  Sad

WHY??

First is the TCP/IP:7319...   What the heck is that 7319, and why is it in there?  

It's one of the multitude of ports which our modern PCs have available for us to use to communicate with things.  How was 7319 chosen?  That was all just Steve, picking an unused port on my PC, and deciding, "I'm ah gonna use dis one!"  Most of the time, our modern routers tend to lock down port access for most people and things.  You have one or two ports open for common stuff (like http and https transfers), but the rest of those ports are locked for security purposes.  

Since there's a zillion different routers, and a zillion different ways they're configured, with a zillion different sets of software to interact with them, *I CAN'T HELP YOU WITH YOUR ROUTER SETTINGS.*  You'll have to Google, dig out the manual that came packaged when you bought the router, or call your ISP and ask them to help.  At the end of the day though, you're NOT going to be able to share communications unless you're sharing on a port that's opened and allows it.  <--This part, unfortunately, you're on your own to puzzle out.  All I can say is "Open your router settings, choose a port you like that's not currently in use, and open it -- however you do that on your router."

Once you've got an open port, and if it's not 7319 like I chose for it to be, then you'd need to change your program to work on the port you've chosen.

Code: (Select All)
    client = _OpenClient("TCP/IP:####:172.83.131.239")

Try that, and it MAY work for you.  Once again, however, I'd be willing to bet against it.  Sad

Once more, go into your router settings, and this time look for PORT FORWARDING.  Most of us have multiple devices set up for the internet.  Our phones are connected, as is our pc, our ipad, our tv, all our damn smart lightbulbs...  You probably need to do a little more specific directing with port forwarding to tell your router where you want to send that open port information to.

Once again, I'm sorry, but I can't really help much with this step as every router has it's own software and way of interacting with you.


[Image: image.png]

Click on the image above, if you want, and it'll show my router's port forwarding setup.  The first three and where I host my own private server from time to time (ports 80 and 443 and http and https traffic, while 3306 is where my SQL Database likes to communicate back and forth when it's up and running).  The last entry in that list, however, is the one of interest for you guys -- Laptop Forwarding on port 7319, and which is going to 10.243.1.77...

That 10.242.1.77 is my laptop's local address on my network.  By setting up port forwarding like this, communications on port 7319 are now routed directly to it, allowing it to communicate with the rest of the world.

Once you've set up the open port, and forwarded it to your machine which is going to run the compiled EXE, chances are you're good to go!!  Your firewall might pop up a question "Do you really want to allow this", but you can feel free to tell it to pisser off.  You've got to let the information travel back and forth to your PC, or else you'll never be able to communicate on an open port like this with the outside world.  




So you run it...  And it works!!  YAAAAAAYYYY!!!

You go to bed, get up the next morning, notice that Windows did an update on you, and it now no longer works.   WTF?!!  (I can just hear some of you cussing already!  No worries -- no judgement.  I've been there as well!!)

Two important things to keep in mind:

1) If you don't have a permanent STATIC IP address (you'll know if you do because you asked for it specifically from your ISP and are paying extra each month for it), then your IP address is dynamically allocated for you.  You'll need to get the new address, swap it into your program, and try it again.

2) And if number one doesn't fix the issue, problem number two is... dum dum de dum... once again dynamic addresses.  That last step that we did, with the port forwarding...  Remember it?  You forwarded your data to a specific local IP address...   If you don't have that configured as a static address (set up manually instead of automatic), then it may not be the same as it was before either.  You may have to go back and change your port forwarding address once again so it works as you'd expect.
Reply


Messages In This Thread
Chat with Me -- HOST - by SMcNeill - 12-11-2022, 12:30 PM
RE: Chat with Me -- HOST - by SMcNeill - 12-11-2022, 12:37 PM
RE: Chat with Me -- HOST - by Pete - 12-11-2022, 05:41 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-11-2022, 06:02 PM
RE: Chat with Me -- HOST - by Pete - 12-11-2022, 06:13 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-11-2022, 07:08 PM
RE: Chat with Me -- HOST - by SMcNeill - 12-11-2022, 08:26 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-11-2022, 08:47 PM
RE: Chat with Me -- HOST - by SMcNeill - 12-11-2022, 08:55 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-11-2022, 09:13 PM
RE: Chat with Me -- HOST - by Pete - 12-11-2022, 11:19 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-11-2022, 11:49 PM
RE: Chat with Me -- HOST - by Pete - 12-12-2022, 12:34 AM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-12-2022, 08:46 AM
RE: Chat with Me -- HOST - by Kernelpanic - 12-13-2022, 12:08 AM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-13-2022, 12:24 AM
RE: Chat with Me -- HOST - by SMcNeill - 12-13-2022, 12:26 AM
RE: Chat with Me -- HOST - by Kernelpanic - 12-13-2022, 03:43 PM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-13-2022, 05:06 PM
RE: Chat with Me -- HOST - by Pete - 12-13-2022, 12:57 AM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-13-2022, 01:22 AM
RE: Chat with Me -- HOST - by Kernelpanic - 12-13-2022, 03:40 PM
RE: Chat with Me -- HOST - by Pete - 12-13-2022, 04:29 PM
RE: Chat with Me -- HOST - by SMcNeill - 12-13-2022, 03:44 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-13-2022, 03:53 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-13-2022, 03:49 PM
RE: Chat with Me -- HOST - by Pete - 12-13-2022, 05:38 PM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-13-2022, 06:34 PM
RE: Chat with Me -- HOST - by Pete - 12-13-2022, 07:00 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-13-2022, 09:23 PM
RE: Chat with Me -- HOST - by Pete - 12-13-2022, 09:29 PM
RE: Chat with Me -- HOST - by SpriggsySpriggs - 12-13-2022, 09:12 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-13-2022, 09:34 PM
RE: Chat with Me -- HOST - by Pete - 12-13-2022, 10:06 PM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-14-2022, 08:35 AM
RE: Chat with Me -- HOST - by Kernelpanic - 12-13-2022, 11:10 PM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-14-2022, 09:52 AM
RE: Chat with Me -- HOST - by SpriggsySpriggs - 12-14-2022, 04:42 PM
RE: Chat with Me -- HOST - by Pete - 12-14-2022, 07:27 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-14-2022, 10:44 PM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-15-2022, 01:48 AM
RE: Chat with Me -- HOST - by Pete - 12-14-2022, 10:52 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-14-2022, 11:27 PM
RE: Chat with Me -- HOST - by SMcNeill - 12-14-2022, 11:35 PM
RE: Chat with Me -- HOST - by Pete - 12-15-2022, 12:04 AM
RE: Chat with Me -- HOST - by SMcNeill - 12-15-2022, 12:09 AM
RE: Chat with Me -- HOST - by TempodiBasic - 12-15-2022, 12:54 AM
RE: Chat with Me -- HOST - by SpriggsySpriggs - 12-15-2022, 02:39 PM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-15-2022, 02:52 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-16-2022, 12:59 AM
RE: Chat with Me -- HOST - by SpriggsySpriggs - 12-15-2022, 02:58 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-16-2022, 12:53 AM
RE: Chat with Me -- HOST - by Pete - 12-16-2022, 02:19 AM
RE: Chat with Me -- HOST - by Kernelpanic - 12-16-2022, 04:56 PM
RE: Chat with Me -- HOST - by mnrvovrfc - 12-16-2022, 11:24 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-16-2022, 10:01 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-17-2022, 05:55 PM
RE: Chat with Me -- HOST - by Pete - 12-17-2022, 06:13 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-17-2022, 08:12 PM
RE: Chat with Me -- HOST - by Kernelpanic - 12-17-2022, 08:54 PM
RE: Chat with Me -- HOST - by Pete - 12-18-2022, 09:33 AM
RE: Chat with Me -- HOST - by Kernelpanic - 12-17-2022, 09:57 PM



Users browsing this thread: 3 Guest(s)