Announcement

Collapse
No announcement yet.

Specify IP for TCP OPEN SERVER

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

  • Specify IP for TCP OPEN SERVER

    Any of you all figured out a way to specify the IP for TCP OPEN SERVER? Or do it in Win API...

  • #2
    1. Port may need to be forwarded to ipv4 address in router software (IPCONFIG at command prompt)
    2. Firewall needs to allow the server program
    Code:
    FUNCTION PBMAIN () AS LONG
     LOCAL sHost      AS STRING
     LOCAL IP,PortNumber,FileNumber,timout AS LONG
     sHost = "192.168.0.2"  'ipv4 address or computer name of server machine
     PortNumber = 80        'port forwarded to server machine ipv4 address in router software
     timout    = 10000
     HOST ADDR sHost TO IP
     IF ISFALSE IP THEN ?  "Invalid IP Address " + sHost:EXIT FUNCTION
     FileNumber = FREEFILE
     TCP OPEN SERVER ADDR IP PORT PortNumber AS FileNumber TIMEOUT timout
     IF ERR THEN
       ? "TCP Open Error" + STR$(ERR)
     ELSE
       ? "Opened"
       TCP CLOSE #FileNumber
     END IF
    END FUNCTION
    https://duckduckgo.com instead of google

    Comment


    • #3
      Your copy of PB Help broken or missing?

      TCP OPEN SERVER [ADDR ip&] {PORT p& | srvc$} AS [#] fNum& [TIMEOUT timeoutval&]

      square brackets indicate optional use items. delete the brackets when using ADDR.

      Cheers,
      Dale

      Comment


      • #4
        Hi Dale - I was under the impression you could only specify a port,not an ip, when opened as a server.
        I need to retry!

        Comment


        • #5
          Originally posted by David Clarke View Post
          Hi Dale - I was under the impression you could only specify a port,not an ip, when opened as a server.
          I need to retry!
          You mean " I need to reread"

          From Help:
          As a server, if you specify the optional ADDR ip&, the TCP server monitors connections at the specified ip& address. Otherwise, the primary IP address for the computer is used by default.

          Comment


          • #6
            I normally use an IP, but it may not be needed.
            Here are 10 servers on the primary ip address.
            Code:
            FUNCTION PBMAIN () AS LONG
             LOCAL PortNumber AS LONG
             DIM hThread(1 TO 10) AS LONG
             FOR PortNumber = 1 TO 10
              THREAD CREATE NewServer(PortNumber) TO hThread(PortNumber)
              THREAD CLOSE hThread(PortNumber) TO hThread(PortNumber)
             NEXT
             DO
              SLEEP 50
             LOOP UNTIL THREADCOUNT = 1
             BEEP
            END FUNCTION
            
            THREAD FUNCTION NewServer(BYVAL PortNumber AS LONG) AS LONG
             LOCAL h AS LONG
             h = FREEFILE
             TCP OPEN SERVER PORT PortNumber AS #h
             IF ERR THEN ? "Could not open port" + STR$(PortNumber)
             SLEEP 3000
             TCP CLOSE #h
            END FUNCTION
            https://duckduckgo.com instead of google

            Comment


            • #7
              [QUOTE=Mike Doty;n782659]I normally use an IP, but it may not be needed.

              It's only needed if the machine has multiple IP addresses (commonly multiple NICs). I guess with the increasing use of IPv6 in addition to IPv4, it will become more important.

              Comment


              • #8
                Just thinking about it. Does PB know about IPv6?

                From Help:
                An IP address consists of four bytes.

                Comment


                • #9
                  https://sockettools.com/sockettools-library-edition/

                  > It's only needed if the machine has multiple IP addresses (commonly multiple NICs). I guess with the increasing use of IPv6 in addition to IPv4, it will become more important.

                  Thanks, Stuart!!
                  Last edited by Mike Doty; 10 Jul 2019, 08:28 AM.
                  https://duckduckgo.com instead of google

                  Comment


                  • #10
                    Just thinking about it. Does PB know about IPv6?
                    Apparently not. (Good question Stuart.)

                    Though as Mike points out, there are work-arounds. (thanx Mike.)

                    If this short-coming was noticed two years ago, maybe we'll get IP6 in PBWin 11/PBCC 7. ((If not noticed, then hopefully 11.03/7.03 or 12/8 (please don't hold up next release to add)))

                    Cheers,
                    Dale

                    Comment

                    Working...
                    X