QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: SMcNeill on November 10, 2020, 01:50:47 pm

Title: Test this and chat with me
Post by: SMcNeill on November 10, 2020, 01:50:47 pm
Code: Text: [Select]
  1. DIM SHARED OUT$, myname$
  2. DIM l AS _UNSIGNED _BYTE
  3.  
  4. PRINT "[Steve's Mini Messenger]"
  5. client = _OPENCLIENT("TCP/IP:7993:172.93.60.23") ' Attempt to connect to Steve's PC host as a client
  6. PRINT "[connected to " + _CONNECTIONADDRESS(client) + "]"
  7.  
  8. INPUT "Enter your name: ", myname$
  9. OUT$ = myname$ + " connected!"
  10. l = LEN(OUT$)
  11. PUT #client, , l
  12. PUT #client, , OUT$
  13. 'PRINT "OUT$: "; OUT$
  14. DO
  15.     GetMessage client
  16.     SendMessage mymessage$, client ' display current input on screen
  17.     _LIMIT 30
  18. LOOP
  19.  
  20. '.................... END OF MAIN PROGRAM ................
  21.  
  22.  
  23. SUB GetMessage (client) ' get & display any new message
  24.     DIM l AS _UNSIGNED _BYTE
  25.     GET #client, , l
  26.     IF l > 0 THEN
  27.         _DELAY .1 'some delay so the other 'puter can send the info to us across spiderman's excretions!
  28.         OUT$ = SPACE$(l)
  29.         GET #client, , OUT$
  30.         VIEW PRINT 1 TO 20
  31.         LOCATE 20, 1
  32.         PRINT OUT$
  33.         VIEW PRINT 1 TO 24
  34.     ELSE
  35.         OUT$ = ""
  36.     END IF
  37. END SUB
  38.  
  39. SUB SendMessage (mymessage$, client) ' simple input handler
  40.     DIM l AS _UNSIGNED _BYTE
  41.     k$ = INKEY$
  42.     IF LEN(k$) THEN
  43.         IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
  44.             mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
  45.         ELSE
  46.             IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$
  47.         END IF
  48.     END IF
  49.     VIEW PRINT 1 TO 24
  50.     LOCATE 22, 1: PRINT SPACE$(80); ' erase previous message displayed
  51.     LOCATE 23, 1: PRINT SPACE$(80); ' erase previous message displayed
  52.     t$ = myname$ + ": " + mymessage$
  53.     LOCATE 22, 1: PRINT t$;
  54.     IF k$ = CHR$(13) OR LEN(t$) = 255 THEN ' [Enter] sends the message
  55.         IF mymessage$ = "" THEN SYSTEM ' [Enter] with no message ends program
  56.         mymessage$ = myname$ + ":" + mymessage$
  57.         l = LEN(mymessage$)
  58.         PUT #client, , l
  59.         PUT #client, , mymessage$
  60.         _TITLE mymessage$
  61.  
  62.         mymessage$ = ""
  63.     END IF
  64.     IF k$ = CHR$(27) THEN SYSTEM ' [Esc] key ends program
  65. END SUB
  66.  

I've finally taken time to set up all the port forwarding and firewall exceptions for my new PC to start working as a webserver once again.  (I think.)  If anyone likes, feel free to try the code above and let me know if you can connect and say "Hi" to whomever might be sitting around and goofing off in the little mini-messenger chat room I'm testing.

Note:  This little room is subject to self-destruct at any time, so if you can't connect, just post a message here and don't worry about it.  Chances are, someone else verified that things are working properly for me, and I've just shut down the experiment afterwards so I can go back about getting my personal web pages back up and such.  :)
Title: Re: Test this and chat with me
Post by: Petr on November 10, 2020, 02:16:15 pm
Hi Steve. Program generate error message "Out of memory" for me.
Title: Re: Test this and chat with me
Post by: Petr on November 10, 2020, 02:18:39 pm
Row 28 do it?
Title: Re: Test this and chat with me
Post by: SMcNeill on November 10, 2020, 02:21:21 pm
Out of memory??

How the heck did I accomplish that!

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Something somewhere isn't working as intended.  Almost 2GB memory for the client???  I'm digging into the issue.
Title: Re: Test this and chat with me
Post by: SpriggsySpriggs on November 10, 2020, 02:32:38 pm
That worked pretty well, Steve. Good luck on finding the memory leak! I'm willing to do more tests for you in the future if need-be.
Title: Re: Test this and chat with me
Post by: SMcNeill on November 10, 2020, 02:34:24 pm
Close the server, restart it, and now my memory usage is running down at around 50-80MB.  Guess I'll let it go for a while and see if the amount creeps up over time.  If so, there's a memory leak in there somewhere, but I don't have a clue where it might actually be at.

At least I got a good test result from it, and it shows that my ports are forwarded properly now, and my firewall exceptions are all working as intended.  Spriggys connected to my system and sent and received information properly, and that was the most important thing that I was wanting to confirm.  Program glitches can be ironed out anytime now; I just needed to see if I could open that remote connection and send/receive data properly, and I'm happy to report that that is a success, at least. :)
Title: Re: Test this and chat with me
Post by: Petr on November 10, 2020, 03:03:36 pm
My output:

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Test this and chat with me
Post by: SMcNeill on November 10, 2020, 03:16:22 pm
Looking at it, I imagine the glitch is in lag over the net.

I bet when I send the length of &H0000000F (in hex, for 15 bytes), you’re receiving it in chunks like:  &H000000 (which is 3 bytes of zero, which is 0), followed by &H0F123456 (which would be that 15 in length + the first 3 bytes of user data transfered).

This is generating you a string of super size, and giving you the mem usage you’re seeing.

Fix would be to send a text limit of 255 characters, and read a single _UNSIGNED _BYTE for the length.  (Or prefix with a single byte as an indicator to prepare for proper data of X size, following.)
Title: Re: Test this and chat with me
Post by: Petr on November 10, 2020, 03:22:06 pm
I run it again under 64bit IDE QB64 v. 1.4 and works fine! Under 32bit QB64 v. 1.5 it do memory leak. I am connected now under QB64 1.4.
Title: Re: Test this and chat with me
Post by: SMcNeill on November 10, 2020, 03:49:54 pm
Chat test server is currently down for investigative purposes.
Title: Re: Test this and chat with me
Post by: MasterGy on November 10, 2020, 04:12:28 pm

Hi ! I tried it ! unfortunately it can be seen in the attached picture, he stopped there, did not go any further. i put it in my own folder and started from there, before that avaston turned off protection. I have win7. i hope this helped something. let me know if you can join! I find it exciting to have a private network communicating on the net.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Test this and chat with me
Post by: badger on November 10, 2020, 04:59:07 pm
Hello

I get a black screen that says "[Steve's Mini Messenger]" then my comput will just lock up for a couple of minutes then i get bad file mode in line six.

Badger
Title: Re: Test this and chat with me
Post by: SMcNeill on November 10, 2020, 05:10:57 pm
Guys...

Quote

Chat test server is currently down for investigative purposes.


You can’t connect to a server that isn’t running...
Title: Re: Test this and chat with me
Post by: TempodiBasic on November 10, 2020, 05:17:33 pm
Hi Steve
I try now your Mini Messenger ...
I got the same position of Badger, and if I click on Yes of Continue? msgbox I got other errors on line 11 12 13 and then 25.... all the same error Bad File Name or Number..
here a screenshot
  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Quote
You cannot connect to a server that is not running... 
LOL you're right! :-))))
Title: Re: Test this and chat with me
Post by: SMcNeill on November 10, 2020, 05:46:52 pm
Since several folks were wanting to have fun and test this, the code in the original post has been fixed and the server is now back up and running again.  Hopefully, the excessive memory issue has been corrected, and things work as they should.  Feel free to pop in and give us a chat anytime you guys want, for the next few hours.

Code: QB64: [Select]
  1. DIM SHARED OUT$, myname$
  2.  
  3. PRINT "[Steve's Mini Messenger]"
  4. client = _OPENCLIENT("TCP/IP:7993:172.93.60.23") ' Attempt to connect to Steve's PC host as a client
  5. PRINT "[connected to " + _CONNECTIONADDRESS(client) + "]"
  6.  
  7. INPUT "Enter your name: ", myname$
  8. OUT$ = myname$ + " connected!"
  9. l = LEN(OUT$)
  10. PUT #client, , l
  11. PUT #client, , OUT$
  12. 'PRINT "OUT$: "; OUT$
  13.     GetMessage client
  14.     SendMessage mymessage$, client ' display current input on screen
  15.     _LIMIT 30
  16.  
  17. '.................... END OF MAIN PROGRAM ................
  18.  
  19.  
  20. SUB GetMessage (client) ' get & display any new message
  21.     GET #client, , l
  22.     IF l > 0 THEN
  23.         _DELAY .1 'some delay so the other 'puter can send the info to us across spiderman's excretions!
  24.         OUT$ = SPACE$(l)
  25.         GET #client, , OUT$
  26.         VIEW PRINT 1 TO 20
  27.         LOCATE 20, 1
  28.         PRINT OUT$
  29.         VIEW PRINT 1 TO 24
  30.     ELSE
  31.         OUT$ = ""
  32.     END IF
  33.  
  34. SUB SendMessage (mymessage$, client) ' simple input handler
  35.     k$ = INKEY$
  36.     IF LEN(k$) THEN
  37.         IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
  38.             mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
  39.         ELSE
  40.             IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$
  41.         END IF
  42.     END IF
  43.     VIEW PRINT 1 TO 24
  44.     LOCATE 22, 1: PRINT SPACE$(80); ' erase previous message displayed
  45.     LOCATE 23, 1: PRINT SPACE$(80); ' erase previous message displayed
  46.     t$ = myname$ + ": " + mymessage$
  47.     LOCATE 22, 1: PRINT t$;
  48.     IF k$ = CHR$(13) OR LEN(t$) = 255 THEN ' [Enter] sends the message
  49.         IF mymessage$ = "" THEN SYSTEM ' [Enter] with no message ends program
  50.         mymessage$ = myname$ + ":" + mymessage$
  51.         l = LEN(mymessage$)
  52.         PUT #client, , l
  53.         PUT #client, , mymessage$
  54.         _TITLE mymessage$
  55.  
  56.         mymessage$ = ""
  57.     END IF
  58.     IF k$ = CHR$(27) THEN SYSTEM ' [Esc] key ends program

(Code reposted here, for convenience's sake, as well as edited and corrected in the original post above.)
Title: Re: Test this and chat with me
Post by: SMcNeill on November 10, 2020, 06:30:00 pm
Server back down again.  This version seemed to work as intended, except it ate one or two of our letters from folks names.  Go figure!  All I can say is it's probably an internet chat tax at work!  Dern overreaching government!
Title: Re: Test this and chat with me
Post by: Kernelpanic on November 11, 2020, 12:08:32 pm
With me, the program finally hangs up at line 26.

Title: Re: Test this and chat with me
Post by: SMcNeill on November 11, 2020, 12:20:30 pm
With me, the program finally hangs up at line 26.

The server is back down again.  It passed the tests I was wanting to run with it, so I’ve closed it for now, once again.
Title: Re: Test this and chat with me
Post by: NOVARSEG on November 16, 2020, 02:03:47 am
 

 IF LEN(k$) THEN
???
Title: Re: Test this and chat with me
Post by: NOVARSEG on November 16, 2020, 02:56:49 am
 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
******************
'or try

 IF LEN(k$) = 1 THEN

        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
        mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        END IF

        IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$
       
END IF

****
Title: Re: Test this and chat with me
Post by: SMcNeill on November 16, 2020, 03:03:47 am
IF LEN(k$) THEN...

The above line is a boolean logic statement.  It’s basically equivalent to:  IF LEN(k$) <> 0 THEN...
Title: Re: Test this and chat with me
Post by: NOVARSEG on November 16, 2020, 03:05:39 am
OK

check my other post  there was an END IF out of place.
Title: Re: Test this and chat with me
Post by: NOVARSEG on November 16, 2020, 04:24:11 pm
If code was
****
IF LEN(k$) THEN
        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
            mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
       
            IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$
        END IF
    END IF
****
'then the condition in line ****IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$****
can't ever be true

'however:
****
 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
****

The ELSE keyword seems to make the code work?? but the following code
****
 IF LEN(k$) = 1 THEN

        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
        mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        END IF

        IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$
       
END IF
****

eliminates the ELSE with a simple rearrangement of an  END IF

The ASC  value is less than 127. Don't know what might happen if characters 127 to 255 are sent.

INKEY$ return a single character so **** IF LEN(k$) = 1 THEN****  should be OK
Title: Re: Test this and chat with me
Post by: SMcNeill on November 16, 2020, 06:04:16 pm
Let me break the snippet down so you can understand what it’s doing.

 IF LEN(k$) THEN   <— This checks to see if we have a keypress

IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN.  <— This checks to see if the key pressed was the BACKSPACE key, and if we have a string of any size

mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1). <— Here, if we have a string, and hit backspace, we erase the last character in that string.

ELSE. <— else we have a key pressed, and it’s not the backspace key, or we don’t have a existing string for mymessage$

IF LEN(k$) = 1 AND ASC(k$) >= 32 THEN mymessage$ = mymessage$ + k$ <— This basically says if the key is CHR$(32) or higher, add it to our string, as long as it’s not a control key like the 2-digit arrow keys.
       
END IF. <— To end the IF...ELSE...block to check for backspace
   
END IF.  <— To end the check for key presses.



So basically, we check for a keypress.  If backspace is pressed, we erase the last character from our string.  Otherwise, as long as it’s not a control key, we add it to our string.

That’s what the above does for us.
Title: Re: Test this and chat with me
Post by: NOVARSEG on November 16, 2020, 06:51:52 pm
Thankyou SMcNeill

OK the following code should do the same thing, without the ELSE

*****
IF LEN(k$) =1 THEN   

        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
        mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        END IF

        IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$
       
END IF
****

What is the maximum string length that can be sent with your code so far?
Title: Re: Test this and chat with me
Post by: NOVARSEG on November 16, 2020, 07:16:07 pm
  .
Title: Re: Test this and chat with me
Post by: SMcNeill on November 16, 2020, 08:27:30 pm
Thankyou SMcNeill

OK the following code should do the same thing, without the ELSE

*****
IF LEN(k$) =1 THEN   

        IF k$ = CHR$(8) AND LEN(mymessage$) <> 0 THEN
        mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
        END IF

        IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$
       
END IF
****

What is the maximum string length that can be sent with your code so far?

String limit at the moment is 255 bytes at a time, but you can send and append multiple strings together, if needed.  The program here was really nothing more than a brief test to check my port forwarding and firewall exceptions, to make certain that data would flow both in and out to my PC from the external networks (such as the internet, or someone else's remote connection).

What you have should basically do the same thing, with one minor exception:

IF ASC(k$) > 31 and  ASC(k$) < 127 THEN mymessage$ = mymessage$ + k$  <-- With this line here, you eliminate extended ASCII characters such as the accented letters.  The original basically just checked for ASC(32) and higher; without the restriction on the extended-ASCII codes.

But, that's the beauty of programming -- there's a million different ways to produce the same effect.  You just need to sort out which one suits your style and is the easiest for you to follow.

Another, even simpler solution, is this one:

   
SELECT CASE k$
    CASE CHR$(8): mymessage$ = LEFT$(mymessage$, LEN(mymessage$) - 1)
    CASE CHR$(32) TO CHR$(255): mymessage$ = mymessage$ + k$       
END IF
       
Title: Re: Test this and chat with me
Post by: NOVARSEG on November 16, 2020, 08:50:45 pm
OK   did the*** ASC(k$) < 127*** for simple keyboard input.

Is it possible to use all the characters  to send a file?

What happens if characters <32 are sent?