Announcement

Collapse
No announcement yet.

Looking for Messenger-Like App

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Looking for Messenger-Like App

    I'd like to set up a one-on-one chat with a co-worker. At most, there might be 3 of us in the loop.

    Basically a "messenger" app. But looking at the various apps floating around, I'm seeing way more complex/capable apps than I want. Plus,

    Does anyone have a suggestion on a very minimal PC-to-PC messaging app? Text only. No video. No Audio. No images. Links may be sent, but active link support is not critical.

    I remember such an app for a LAN, but in this case the co-worker is in a different city.

  • #2
    Or, for that matter, if it was easy enough to write something like that in PowerBASIC, I'd be willing to consider that too.

    Comment


    • #3
      ...co-worker is in a different city...
      Oops, what I posted was for a lan.
      [So stuff removed]

      Comment


      • #4
        Just use bog-standard Skype/Discord/IRC/etc. You don't have to use features that are above and beyond standard text messaging if that's all you need them for, but they might be nice to have if you decide you want to voice chat or whiteboard in the future

        Heck you could even use Twitter DMs or Facebook messaging since those need even less setup

        Comment


        • #5
          I'd also be interested in a roll your own IPV6 app. Thanks

          Comment


          • #6
            Hi Bob!
            Yes, I'm using Skype right now, and it works fine for me. But as is the case with a lot of stuff I'm doing right now, folks I'm dealing with suffer from various vision impairments. So I need to be able to control the interface design. Skype is a good example of apps my folks cannot use because of the small size and low color contrast of its GUI design elements (small images/buttons/text, etc.).

            Jim,
            I may give it a try, but what I'd come up with would likely be very minimal - trivial by comparison of the feature-set any of the current IMs offer. It would suit my needs, but would be feature-poor by today's standards.

            Comment


            • #7
              I don't know about setting text size, but ICQ seems alive. I have not used for decade, or more, but was able to go to www.icq.com
              Dale

              Comment


              • #8
                ISTM that combining the code in EchoServ and EClient with a suitable dialog would meet your requirements quite easily.

                (They can be found in ../Samples/Internet/TCP)

                Comment


                • #9
                  Originally posted by Gary Beene View Post
                  Or, for that matter, if it was easy enough to write something like that in PowerBASIC, I'd be willing to consider that too.
                  Hello Gary,
                  If you don't mind learning a new API, consider, for example, the Twitter API.

                  A Google search for twitter api vb6 should get you started towards a PB Application.

                  It's too bad that application developers don't take into consideration that people our age have a more difficult time reading such small print on a screen. However, with your PowerBASIC programming knowledge and skills, you should be able to make your own app.

                  Note that the Twitter API is just an example. There are other API options.

                  Joe

                  Comment


                  • #10
                    ISTM that combining the code in EchoServ and EClient with a suitable dialog would meet your requirements quite easily.
                    That was my thought, too, as soon as all the limitations were spelled out. (3 users, all text): A simple TCP application.

                    OR ... you could pull this off using PCAnywhere (tm), which is not very expensive at all and offers a whole lot of features over and above "chat." I have used the "chat" feature with several of my clients over the years and it works just fine.

                    OR... I think the major "meeting" software such as GoToMeeting, dimdim, etc all have a feature like this, too; but now you are getting into some significant dollars if you need to set up a "host" or "home" site.

                    OR... you could always try this other piece of technology called the "telephone." I used that quite effectively for many years before there was such a thing as a world-wide web or a Windows O/S. Hell, I used that before the first personal-sized computers and it worked well then, too. .

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Gary, I see some web php chat code for download.
                      I am not sure of your full needs or how well it works.
                      It seems no matter what you do. There likely needs to be a sever if some kind involved.
                      p purvis

                      Comment


                      • #12
                        Gary,
                        This should have all the TCP needed.
                        Each instance is a client and server.
                        Reverse $Host and $ClientIp on machine 2.
                        I pulled code out of a program I use as a TCP File Server so it can also be used to send binary.

                        Code:
                        #PBFORMS CREATED V2.01
                        $ValidUser = CHR$(0,1) 'username
                        $Host     = "192.168.0.2"     'my IP or computer name
                        $ClientIp = "192.168.0.3" 'ip of other machine
                        %Port = 51234
                        %TCP_TIMEOUT = 80000
                        %ListenFileNumber = 9999
                        %Tcp_Notify = %WM_USER + 4093
                        GLOBAL ghDlg AS DWORD, gsAll AS STRING 'only for testing
                        THREADED tTCPFileNumber AS LONG 'each connection
                        '-----------------------------------------------------------------------------------
                        #PBFORMS BEGIN INCLUDES
                        #INCLUDE ONCE "WIN32API.INC"
                        #PBFORMS END INCLUDES
                        #PBFORMS BEGIN CONSTANTS
                        %TEXTBOX1    = 1001
                        %IDM_CLEAR   = 2001
                        %IDM_DISPLAY = 2002
                        %TEXTBOX2    = 2003
                        %IDM_SEND    = 2004
                        #PBFORMS END CONSTANTS
                        #PBFORMS DECLARATIONS
                        '------------------------------------------------------------------------------
                        THREAD FUNCTION ConnectionMain(BYVAL tcpfilenumber AS LONG) AS LONG
                        
                         LOCAL sPacket          AS STRING
                         LOCAL sBuffer          AS STRING
                         LOCAL BytesToReceive   AS DWORD
                         LOCAL BytesLeft        AS DWORD
                         LOCAL StartByte        AS DWORD
                        
                         tTcpFileNumber = tcpFileNumber 'so we send back to correct user
                        
                        DO 'check first 6-bytes and sUser$
                         sPacket = ""
                        
                         TCP RECV tcpFilenumber,6,sBuffer
                         IF ERR OR LEN(sBuffer) = 0 THEN EXIT DO
                         IF LEN(sBuffer) < 6 THEN logit USING$("[# byte_, needed 6]",LEN(sBuffer)):BEEP:SLEEP %TCP_TIMEOUT:EXIT DO '(wait,browsers retry) close, finish thread
                         IF MID$(sBuffer,5) <> $ValidUser THEN
                            BEEP:logit "invalid user, SLEEP" + STR$(%TCP_TIMEOUT)
                            SLEEP %TCP_TIMEOUT
                            BEEP:logit "tired of waiting, so finishing thread"
                            EXIT DO 'then TCP CLOSE, exit thread
                         END IF
                        
                         BytesToReceive  = CVDWD(sBuffer)  'don't process strings over 100 (500MB about max in 32-bit)
                         IF bytesToReceive > 200000000 THEN logit USING$("#, over 200 million bytes",BytesToReceive):EXIT DO
                        
                         BytesLeft = BytesToReceive
                         IF ERR OR BytesLeft = 0 THEN EXIT DO 'nothing left to do
                         sPacket = SPACE$(BytesToReceive)     'allocate space once
                         StartByte = 1
                        
                         DO
                          TCP RECV tcpfilenumber,BytesLeft, sBuffer
                          IF ERR OR LEN(sBuffer) = 0 THEN EXIT DO
                        
                          MID$(sPacket,StartByte) = sBuffer
                          StartByte = StartByte + LEN(sBuffer)
                          BytesLeft = BytesLeft-LEN(sBuffer)
                        
                          IF BytesLeft = 0  THEN
                           Logit sPacket
                           REM TCP SEND TcpFileNumber, MKDWD$(LEN(sPacket)) + $ValidUser + sPacket 'ECHO BACK
                           EXIT DO
                          END IF
                         LOOP 'wait for more data
                        LOOP  'done waiting for data
                         SELECT CASE AS LONG ERR
                          CASE  0
                          CASE 24  :Logit USING$("time-out thread #",tcpfilenumber)
                          CASE 57  :logit USING$("dropped connection #",tcpfilenumber,tcpfilenumber)
                          CASE ELSE:logit USING$("untrapped error # in thread #",ERR,tcpfilenumber)
                         END SELECT
                        
                         TCP CLOSE tcpfilenumber
                        END FUNCTION
                        '-----------------------------------------------------------------------------------
                        FUNCTION PBMAIN()
                          LOCAL hParent AS DWORD
                          LOCAL lRslt AS LONG
                        #PBFORMS BEGIN DIALOG %IDD_DIALOG1->%IDR_MENU1->
                          LOCAL hDlg   AS DWORD
                          LOCAL hFont1 AS DWORD
                          LOCAL hFont2 AS DWORD
                        
                          DIALOG NEW hParent, "", 360, 153, 662, 347, %WS_POPUP OR %WS_BORDER OR _
                            %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
                            %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR _
                            %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR _
                            %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                          CONTROL ADD TEXTBOX, hDlg, %TEXTBOX1, "", 5, 10, 650, 155, %WS_CHILD OR _
                            %WS_VISIBLE OR %WS_HSCROLL OR %WS_VSCROLL OR %ES_LEFT OR %ES_MULTILINE _
                            OR %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT _
                            OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
                          CONTROL ADD TEXTBOX, hDlg, %TEXTBOX2, "PowerBASIC Rocks!", 5, 175, 590, 75, %WS_CHILD OR _
                            %WS_VISIBLE OR %WS_TABSTOP OR %WS_HSCROLL OR %WS_VSCROLL OR %ES_LEFT OR _
                            %ES_MULTILINE OR %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL OR %ES_WANTRETURN, _
                            %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _
                            %WS_EX_RIGHTSCROLLBAR
                        
                          FONT NEW "Courier New", 8, 0, %ANSI_CHARSET TO hFont1
                          FONT NEW "MS Sans Serif", 12, 0, %ANSI_CHARSET TO hFont2
                        
                          CONTROL SET FONT hDlg, %TEXTBOX1, hFont1
                          CONTROL SET FONT hDlg, %TEXTBOX2, hFont2
                        
                          AttachMENU1 hDlg
                        #PBFORMS END DIALOG
                          ghDlg = hDlg
                          StartListener
                          DIALOG SHOW MODAL hDlg CALL MyCallBack
                          FUNCTION = lRslt
                        END FUNCTION
                        '------------------------------------------------------------------------------
                        SUB LogIt(s AS STRING) THREADSAFE
                         gsAll+=s + $CRLF
                         CONTROL SET TEXT ghDlg, %TEXTBOX1,gsAll
                         CONTROL SEND ghDlg,%TEXTBOX1,%WM_VSCROLL,%SB_BOTTOM,0  'takes time!
                        END SUB
                        '------------------------------------------------------------------------------
                        FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
                        #PBFORMS BEGIN MENU %IDR_MENU1->%IDD_DIALOG1
                          LOCAL hMenu   AS DWORD
                        
                          MENU NEW BAR TO hMenu
                          MENU ADD STRING, hMenu, "Clear", %IDM_CLEAR, %MF_ENABLED
                          MENU ADD STRING, hMenu, "Display", %IDM_DISPLAY, %MF_ENABLED
                          MENU ADD STRING, hMenu, "Send", %IDM_SEND, %MF_ENABLED
                        
                          MENU ATTACH hMenu, hDlg
                        #PBFORMS END MENU
                          FUNCTION = hMenu
                        END FUNCTION
                        '------------------------------------------------------------------------------
                        SUB StartListener
                         LOCAL lhIPAddress    AS DWORD   'listen ip as dword
                         LOCAL nListenSocket  AS DWORD   'listen socket
                        
                         HOST ADDR $Host TO lhIPAddress  'Convert to IP addr
                         IF ISFALSE lhIPAddress THEN LogIt "Invalid IP Address " + $Host
                        
                         TCP OPEN SERVER ADDR lhIPAddress PORT %Port AS %ListenFileNumber TIMEOUT %TCP_TIMEOUT
                         IF ERR THEN
                            ? "Unable to open port " + STR$(%Port) + " on host " & $Host,%MB_SYSTEMMODAL,ERROR$ + STR$(ERR)
                            EXIT SUB
                         END IF
                         TCP NOTIFY %ListenFileNumber, ACCEPT TO ghDlg AS %Tcp_Notify        'notify of connections
                         DIALOG SET TEXT ghDlg,USING$("host &     port #     TimeOut # ms",$Host,%Port,%TCP_TIMEOUT)
                        END SUB
                        
                        '------------------------------------------------------------------------------
                        CALLBACK FUNCTION MyCallBack
                          LOCAL NewTcpFileNumber,h AS LONG
                        
                         SELECT CASE AS LONG CB.MSG
                        
                          CASE %TCP_NOTIFY
                           IF LO(WORD, CB.LPARAM) = %FD_ACCEPT THEN
                            NewTcpFileNumber = FREEFILE
                            TCP ACCEPT %ListenFileNumber AS NewTcpFileNumber
                            THREAD CREATE ConnectionMain(NewTcpFileNumber) TO h
                            THREAD CLOSE h TO h
                            SLEEP 5
                           END IF
                        
                           CASE %WM_INITDIALOG
                             ghDlg = CB.HNDL
                        
                           CASE %WM_COMMAND
                            SELECT CASE AS LONG CB.CTL
                        
                              CASE %IDM_CLEAR
                               gsAll = ""
                               CONTROL SET TEXT CB.HNDL,%TEXTBOX1,gsAll
                        
                              CASE %IDM_Display
                               CONTROL SET TEXT ghDlg, %TEXTBOX1,USING$("Total bytes #",LEN(gsAll))
                               CONTROL SEND ghDlg,%TEXTBOX1,%WM_VSCROLL,%SB_BOTTOM,0
                        
                              CASE %IDM_SEND
                                LOCAL s AS STRING
                                CONTROL GET TEXT ghDlg,%TEXTBOX2 TO s
                                IF LEN(s) THEN
                                  CONTROL SET TEXT ghDlg,%TEXTBOX2,""
                                  ClientSend $ValidUser,$ClientIp,%port,s  'open new connection
                                  Logit "ME> " +s
                                ELSE
                                  BEEP
                                END IF
                                CONTROL SET FOCUS ghDlg,%TEXTBOX2        '
                        
                            END SELECT
                        
                         END SELECT
                        END FUNCTION
                        '-----------------------------------------------------------------------------------
                        FUNCTION ClientSend(sUser AS STRING,sHost AS STRING,portnumber AS LONG,sSendThis AS STRING) AS LONG
                          LOCAL TcpFileNumber AS LONG
                          LOCAL sBuffer          AS STRING
                          LOCAL BytesToReceive   AS DWORD
                          LOCAL BytesLeft        AS DWORD
                          LOCAL BytesReceived    AS DWORD
                          LOCAL StartByte        AS DWORD
                          TcpFileNumber = FREEFILE   'send data:4-bytes dword length of sSend$ + sUser$ + sSend$
                          TCP OPEN PORT PortNumber AT shost AS #TcpFileNumber
                          IF ERR THEN FUNCTION = ERR:EXIT FUNCTION
                          TCP SEND TcpFileNumber, MKDWD$(LEN(sSendThis)) + suser + sSendThis
                          IF ERR THEN FUNCTION = ERR:TCP CLOSE #TcpFileNumber:EXIT FUNCTION
                          TCP CLOSE tcpfilenumber
                        END FUNCTION
                        How long is an idea?

                        Comment


                        • #13
                          You need to have a look at Slack. It's free for smaller teams (like yours) and is absolutely fantastic for developers/devops-kinda organizations. It ties into so many useful dev-related services (e.g. Github, see the workflow description).

                          If you don't want to trust a cloud service, Mastodon is a self-hosted Slack clone.

                          And if you happen to have an Office 365 account, MS Teams is included, which is MS' Slack clone. And that MS felt the need to create a clone of an existing service, should give you an idea of the importance of Slack.

                          Comment


                          • #14
                            I wrote a simple one about 25 years ago but the code is corporate proprietary and at this stage quite old but here some things I had to think about...
                            • Is this Peer to peer communications only or is central server coordinated communications (central server may be required if you want more then 2 people chatting unless you do complex pass alongs between the peers)
                            • Is this local only or will it traverse the internet, if internet based you will need to be concerned about opening ports on routers and/or firewalls
                            • Also, if on the internet, you really MUST be concerned about security of the data... so strong, standards based, encryption is a must. Even if you "think" it won't need it, you should do it. You never know what people will type and who might be eavesdropping
                            • Will this be text only? Allow pictures, emoticon images, Plain text vs RTF, unicode, allow bold/italics/underlines, colors, etc
                            <b>George W. Bleck</b>
                            <img src='http://www.blecktech.com/myemail.gif'>

                            Comment


                            • #15
                              Some other thoughts...

                              You might want to look at different XMPP protocol clients that support visual impairment capabilities (e.g. https://github.com/rhcarvalho/xmppvox)

                              Alternately, if there is a web based one it might be fairly simple enough to change the CSS or embedded font descriptions to use larger or high contrast schemes.
                              <b>George W. Bleck</b>
                              <img src='http://www.blecktech.com/myemail.gif'>

                              Comment


                              • #16
                                I wrote a simple one about 25 years ago...
                                So did I ... but that did not use TCP or "clients" or anything like that... it was all written on top of PB "OPEN COM..."

                                That was two-way chat only, not a 'party line' but I'm not quite sure what Gary wants here... "chat" to me means, "exactly two parties at any one time."
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  We use google hangouts at work but I've written an in-browser messager using PB on the back end. If you want a desktop solution then Mike's solution is probably the way to go.

                                  Comment


                                  • #18
                                    All,

                                    For those that were wondering here is Gary's requirement:
                                    I remember such an app for a LAN, but in this case the co-worker is in a different city.


                                    Very funny MCM. Good thing this Blog is not a telephone conversation. Humans have a problem sending and receiving (when performed at the same time) by any historical method. "Oh, let me see did he send 10 drum beats or 9 in the middle of my drum roll?"

                                    Comment


                                    • #19
                                      Jim,
                                      Did someone post anything that didn't work over the internet?

                                      Change the destination IP to your own remote IP and this can be tested over the internet on a single machine as long as port or app is allowed through firewall.
                                      I added some resizing code and changed menu item Send to &Send so Alt+S will send.

                                      Code:
                                      #PBFORMS CREATED V2.01
                                      $ValidUser = CHR$(0,1) 'username
                                      $Host     = "192.168.0.2"  'my IP or computer name
                                      $ClientIp = "192.168.0.2"  'send back to myself
                                      %Port     = 51234
                                      %TCP_TIMEOUT = 10000
                                      %ListenFileNumber = 9999
                                      %Tcp_Notify = %WM_USER + 4093
                                      GLOBAL ghDlg AS DWORD, gsAll AS STRING 'only for testing
                                      THREADED tTCPFileNumber AS LONG        'each connection
                                      '-----------------------------------------------------------------------------------
                                      #PBFORMS BEGIN INCLUDES
                                      #INCLUDE ONCE "WIN32API.INC"
                                      #PBFORMS END INCLUDES
                                      #PBFORMS BEGIN CONSTANTS
                                      %TEXTBOX1    = 1001
                                      %IDM_CLEAR   = 2001
                                      %IDM_DISPLAY = 2002
                                      %TEXTBOX2    = 2003
                                      %IDM_SEND    = 2004
                                      
                                      #PBFORMS END CONSTANTS
                                      #PBFORMS DECLARATIONS
                                      '------------------------------------------------------------------------------
                                      THREAD FUNCTION ConnectionMain(BYVAL tcpfilenumber AS LONG) AS LONG
                                      
                                       LOCAL sPacket          AS STRING
                                       LOCAL sBuffer          AS STRING
                                       LOCAL BytesToReceive   AS DWORD
                                       LOCAL BytesLeft        AS DWORD
                                       LOCAL StartByte        AS DWORD
                                      
                                       tTcpFileNumber = tcpFileNumber 'so we send back to correct user
                                      
                                      DO 'check first 6-bytes and sUser$
                                       sPacket = ""
                                      
                                       TCP RECV tcpFilenumber,6,sBuffer
                                       IF ERR OR LEN(sBuffer) = 0 THEN EXIT DO
                                       IF LEN(sBuffer) < 6 THEN logit USING$("[# byte_, needed 6]",LEN(sBuffer)):BEEP:SLEEP %TCP_TIMEOUT:EXIT DO '(wait,browsers retry) close, finish thread
                                       IF MID$(sBuffer,5) <> $ValidUser THEN
                                          BEEP:logit "invalid user, SLEEP" + STR$(%TCP_TIMEOUT)
                                          SLEEP %TCP_TIMEOUT
                                          BEEP:logit "tired of waiting, so finishing thread"
                                          EXIT DO 'then TCP CLOSE, exit thread
                                       END IF
                                      
                                       BytesToReceive  = CVDWD(sBuffer)  'don't process strings over 100 (500MB about max in 32-bit)
                                       IF bytesToReceive > 200000000 THEN logit USING$("#, over 200 million bytes",BytesToReceive):EXIT DO
                                      
                                       BytesLeft = BytesToReceive
                                       IF ERR OR BytesLeft = 0 THEN EXIT DO 'nothing left to do
                                       sPacket = SPACE$(BytesToReceive)     'allocate space once
                                       StartByte = 1
                                      
                                       DO
                                        TCP RECV tcpfilenumber,BytesLeft, sBuffer
                                        IF ERR OR LEN(sBuffer) = 0 THEN EXIT DO
                                      
                                        MID$(sPacket,StartByte) = sBuffer
                                        StartByte = StartByte + LEN(sBuffer)
                                        BytesLeft = BytesLeft-LEN(sBuffer)
                                      
                                        IF BytesLeft = 0  THEN
                                         Logit sPacket
                                         REM TCP SEND TcpFileNumber, MKDWD$(LEN(sPacket)) + $ValidUser + sPacket 'ECHO BACK
                                         EXIT DO
                                        END IF
                                       LOOP 'wait for more data
                                      LOOP  'done waiting for data
                                       SELECT CASE AS LONG ERR
                                        CASE  0
                                        CASE 24  :Logit USING$("time-out thread #",tcpfilenumber)
                                        CASE 57  :logit USING$("dropped connection #",tcpfilenumber,tcpfilenumber)
                                        CASE ELSE:logit USING$("untrapped error # in thread #",ERR,tcpfilenumber)
                                       END SELECT
                                      
                                       TCP CLOSE tcpfilenumber
                                      END FUNCTION
                                      '-----------------------------------------------------------------------------------
                                      FUNCTION PBMAIN()
                                        LOCAL hParent AS DWORD
                                        LOCAL lRslt AS LONG
                                      #PBFORMS BEGIN DIALOG %IDD_DIALOG1->%IDR_MENU1->
                                        LOCAL hDlg   AS DWORD
                                        LOCAL hFont1 AS DWORD
                                      
                                        DIALOG NEW PIXELS,hParent, "", 0 ,0, 600, 600, %WS_POPUP OR %WS_BORDER OR _
                                          %WS_DLGFRAME OR %WS_THICKFRAME OR %WS_CAPTION OR %WS_SYSMENU OR _
                                          %WS_MINIMIZEBOX OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR %DS_MODALFRAME OR _
                                          %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR _
                                          %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                                        CONTROL ADD TEXTBOX, hDlg, %TEXTBOX1, "", 0, 0, 500, 100, %WS_CHILD OR _
                                          %WS_VISIBLE OR %WS_HSCROLL OR %WS_VSCROLL OR %ES_LEFT OR %ES_MULTILINE _
                                          OR %ES_AUTOHSCROLL OR %ES_AUTOVSCROLL, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT _
                                          OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
                                        CONTROL ADD TEXTBOX, hDlg, %TEXTBOX2, "PowerBASIC Rocks!", 0, 100, 500, _
                                          100, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %WS_HSCROLL OR _
                                          %WS_VSCROLL OR %ES_LEFT OR %ES_MULTILINE OR %ES_AUTOHSCROLL OR _
                                          %ES_AUTOVSCROLL OR %ES_WANTRETURN, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT OR _
                                          %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR
                                      
                                        FONT NEW "Courier New", 8, 0, %ANSI_CHARSET TO hFont1
                                      
                                        CONTROL SET FONT hDlg, %TEXTBOX1, hFont1
                                        CONTROL SET FONT hDlg, %TEXTBOX2, hFont1
                                      
                                        AttachMENU1 hDlg
                                      #PBFORMS END DIALOG
                                        ghDlg = hDlg
                                        StartListener
                                        DIALOG SHOW MODAL hDlg CALL MyCallBack
                                        FUNCTION = lRslt
                                      END FUNCTION
                                      '------------------------------------------------------------------------------
                                      SUB LogIt(s AS STRING) THREADSAFE
                                       gsAll+=s + $CRLF
                                       CONTROL SET TEXT ghDlg, %TEXTBOX1,gsAll
                                       CONTROL SEND ghDlg,%TEXTBOX1,%WM_VSCROLL,%SB_BOTTOM,0  'takes time!
                                      END SUB
                                      '------------------------------------------------------------------------------
                                      FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD
                                      #PBFORMS BEGIN MENU %IDR_MENU1->%IDD_DIALOG1
                                        LOCAL hMenu   AS DWORD
                                      
                                        MENU NEW BAR TO hMenu
                                        MENU ADD STRING, hMenu, "Clear", %IDM_CLEAR, %MF_ENABLED
                                        MENU ADD STRING, hMenu, "Display", %IDM_DISPLAY, %MF_ENABLED
                                        MENU ADD STRING, hMenu, "&Send", %IDM_SEND, %MF_ENABLED
                                      
                                        MENU ATTACH hMenu, hDlg
                                      #PBFORMS END MENU
                                        FUNCTION = hMenu
                                      END FUNCTION
                                      '------------------------------------------------------------------------------
                                      SUB StartListener
                                       LOCAL lhIPAddress    AS DWORD   'listen ip as dword
                                       LOCAL nListenSocket  AS DWORD   'listen socket
                                      
                                       HOST ADDR $Host TO lhIPAddress  'Convert to IP addr
                                       IF ISFALSE lhIPAddress THEN LogIt "Invalid IP Address " + $Host
                                      
                                       TCP OPEN SERVER ADDR lhIPAddress PORT %Port AS %ListenFileNumber TIMEOUT %TCP_TIMEOUT
                                       IF ERR THEN
                                          ? "Unable to open port " + STR$(%Port) + " on host " & $Host,%MB_SYSTEMMODAL,ERROR$ + STR$(ERR)
                                          EXIT SUB
                                       END IF
                                       TCP NOTIFY %ListenFileNumber, ACCEPT TO ghDlg AS %Tcp_Notify        'notify of connections
                                       DIALOG SET TEXT ghDlg,USING$("host &     port #     TimeOut # ms",$Host,%Port,%TCP_TIMEOUT)
                                      END SUB
                                      
                                      '------------------------------------------------------------------------------
                                      CALLBACK FUNCTION MyCallBack
                                        LOCAL NewTcpFileNumber,h AS LONG
                                      
                                       SELECT CASE AS LONG CB.MSG
                                      
                                        CASE %TCP_NOTIFY
                                         IF LO(WORD, CB.LPARAM) = %FD_ACCEPT THEN
                                          NewTcpFileNumber = FREEFILE
                                          TCP ACCEPT %ListenFileNumber AS NewTcpFileNumber
                                          THREAD CREATE ConnectionMain(NewTcpFileNumber) TO h
                                          THREAD CLOSE h TO h
                                          SLEEP 5
                                         END IF
                                      
                                         CASE %WM_INITDIALOG
                                           ghDlg = CB.HNDL
                                           ExpandAndCenterDialog 'expands or contracts size
                                         CASE %WM_SIZE
                                            resize
                                      
                                         CASE %WM_COMMAND
                                          SELECT CASE AS LONG CB.CTL
                                            CASE %IDM_CLEAR
                                             gsAll = ""
                                             CONTROL SET TEXT CB.HNDL,%TEXTBOX1,gsAll
                                      
                                            CASE %IDM_Display
                                             CONTROL SET TEXT ghDlg, %TEXTBOX1,USING$("Total bytes #",LEN(gsAll))
                                             CONTROL SEND ghDlg,%TEXTBOX1,%WM_VSCROLL,%SB_BOTTOM,0
                                      
                                            CASE %IDM_SEND
                                              LOCAL s AS STRING
                                              CONTROL GET TEXT ghDlg,%TEXTBOX2 TO s
                                              IF LEN(s) = 0 THEN s = "Sent nothing at " + TIME$
                                              IF LEN(s) THEN
                                                CONTROL SET TEXT ghDlg,%TEXTBOX2,""
                                                ClientSend $ValidUser,$ClientIp,%port,s  'open new connection
                                                'Logit "ME> " +s
                                              ELSE
                                                BEEP
                                              END IF
                                              CONTROL SET FOCUS ghDlg,%TEXTBOX2        '
                                      
                                          END SELECT
                                      
                                       END SELECT
                                      END FUNCTION
                                      '-----------------------------------------------------------------------------------
                                      FUNCTION ClientSend(sUser AS STRING,sHost AS STRING,portnumber AS LONG,sSendThis AS STRING) AS LONG
                                        LOCAL TcpFileNumber AS LONG
                                        LOCAL sBuffer          AS STRING
                                        LOCAL BytesToReceive   AS DWORD
                                        LOCAL BytesLeft        AS DWORD
                                        LOCAL BytesReceived    AS DWORD
                                        LOCAL StartByte        AS DWORD
                                        TcpFileNumber = FREEFILE   'send data:4-bytes dword length of sSend$ + sUser$ + sSend$
                                        TCP OPEN PORT PortNumber AT shost AS #TcpFileNumber
                                        IF ERR THEN FUNCTION = ERR:EXIT FUNCTION
                                        TCP SEND TcpFileNumber, MKDWD$(LEN(sSendThis)) + suser + sSendThis
                                        IF ERR THEN FUNCTION = ERR:TCP CLOSE #TcpFileNumber:EXIT FUNCTION
                                        TCP CLOSE tcpfilenumber
                                      END FUNCTION
                                      
                                      SUB ExpandAndCenterDialog
                                        LOCAL ScreenWidth,ScreenHeight,DialogWidth,DialogHeight,DialogLeft,DialogTop AS LONG
                                        DIALOG GET SIZE ghdlg TO DialogWidth,DialogHeight
                                        DESKTOP GET SIZE TO ScreenWidth,ScreenHeight
                                        DIALOG SET SIZE ghDlg, ScreenWidth\2,ScreenHeight\2
                                        DIALOG SET LOC  ghDlg, (ScreenWidth\2)-(DialogWidth\2),(ScreenHeight\2)-(DialogHeight\2)
                                      END SUB
                                      
                                      SUB Resize
                                        LOCAL TheWidth,TheHeight AS LONG
                                        DIALOG GET SIZE ghDlg TO TheWidth,TheHeight
                                        TheHeight=TheHeight-68 'using pixels in dialog
                                        CONTROL SET SIZE   ghDlg, %TEXTBOX1, TheWidth-20,TheHeight*.8
                                        CONTROL SET SIZE   ghDlg, %TEXTBOX2, TheWidth-20,TheHeight*.2
                                        CONTROL SET LOC    ghDlg, %TEXTBOX2, 0,TheHeight*.8
                                      END SUB
                                      How long is an idea?

                                      Comment


                                      • #20
                                        Mike,
                                        Looks like just standard LAN to me. I'm thinking MQTT would be the way to go for this. Hopefully Jerry Wilson will chime in here. He was working in that direction for IoT sensors. Obviously IPV6 should make this sort of communication very easy. Anyone willing to share?

                                        Comment

                                        Working...
                                        X