Announcement

Collapse
No announcement yet.

Maximum TCP packet length 1460?

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

  • Maximum TCP packet length 1460?

    'Example, send a packet of 3000 and it returns 2,920 bytes?
    'Send packets from 1-byte to 1460 and never an error.

    'Is this a program error or perhaps adjustable on each machine?
    'Buffer over-run, perhaps?

    'Ive tested this for days and can't get reliable results with a packet over 1460 bytes.

    'This program is Echo client (which comes with PB) modified to send
    'many requests to the EchoServ with the LogEvent removed.


    Got tab stops back,some how?

    Code:
     
    'Why does this only return 2,920 bytes?
    #COMPILE EXE
    #DIM ALL
    %MaximumPacket1460 = 1460 
    $SERVER = ""
    FUNCTION PBMAIN () AS LONG
        LOCAL buffersize AS LONG
        LOCAL Attempt AS LONG
        LOCAL PacketLength  AS LONG     'don't exceed 1460
        LOCAL nSocket AS LONG
        LOCAL sBuffer AS STRING
        LOCAL sPacket AS STRING
        LOCAL totalBytesSent AS DWORD
        TCP OPEN PORT 999 AT "192.168.0.100" AS nSocket TIMEOUT 5000
        IF ERR THEN
            ? "Error opening port: " + STR$(ERR)
            EXIT FUNCTION
        END IF
    FOR Attempt = 1 TO 1000
        PacketLength = 3000       'do not send packets larger than 1460 bytes
        'IF PacketLength > %MaximumPacket1460 THEN
        '  ? "Sorry, unpredictable results can happen with a buffer larger than 1460"
        '  EXIT FUNCTION
        'END IF
        IF LEN(COMMAND$) THEN
            TCP PRINT nSocket, COMMAND$;
        ELSE
            TCP SEND nSocket, STRING$(PacketLength,"X")
        END IF
        ERRCLEAR
        sPacket = ""
        DO
            TCP RECV nSocket, 8192, sBuffer
            sPacket = sPacket + sBuffer
        LOOP UNTIL sBuffer = "" OR ISTRUE EOF(nSocket) OR ISTRUE ERR
        IF ERR THEN
          IF ERR = 24 THEN ? "Request has timed-out on the client on attempt"+ STR$(Attempt):EXIT FUNCTION
          ? "Error in client" + STR$(ERRCLEAR)
        END IF
        IF LEN(sPacket) <> PacketLength THEN
           ? "Failed on attempt" + STR$(Attempt) + " packet returned" + STR$(LEN(sPacket))
            EXIT FUNCTION
        END IF
        TotalBytesSent = TotalBytesSent + LEN(sPacket)
    NEXT
        ? "No errors, bytes received back " + FORMAT$(TotalBytesSent,"#,")
         TCP CLOSE nSocket
    END FUNCTION
    Last edited by Mike Doty; 6 Feb 2009, 01:32 AM. Reason: tcpSaveReceive
    CMD shortcut to open any location:
    %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
    Change to run as administrator
    How long is an idea? Write it down.

  • #2
    interesting! Mike, is it a rented server?, if so have you tried different ports?

    Comment


    • #3
      No, this is simply running the echo server and the echo client on a machine without going down the network.
      This has caused me many hours of grief. Reposted and got the tab stop back in. Not sure what I do wrong to lose them.
      Am I missing a required SLEEP somwhere (other than requiring some here and haven't eatten anything in 18 hours.)
      Last edited by Mike Doty; 4 Feb 2009, 09:46 PM.
      CMD shortcut to open any location:
      %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
      Change to run as administrator
      How long is an idea? Write it down.

      Comment


      • #4
        Mike, this might help?, run one instance of each of the following;

        I just sent a 21335 byte file from one to the other and it worked, funny, though while sending that large a file it also sent an additional 0 bytes?


        Code:
        #COMPILE EXE
        #DIM ALL
        #INCLUDE  "WIN32API.INC"
        #INCLUDE  "WS2_32.INC"
        
        %TCP_ACCEPT = %WM_USER + 4093
        %TCP_ECHO   = %WM_USER + 4094
        $SERVER = ""    '172.137.42.188"
        
        GLOBAL hList AS LONG
        DECLARE CALLBACK FUNCTION DlgProc() AS LONG
        '------------------------------------------------------------------------------
        FUNCTION PBMAIN
            LOCAL hDlg&, Msg AS tagMsg, ctext$
            ctext$="test"
            DIALOG NEW %HWND_DESKTOP, "Chat Works400:A",100,100,250,160, _
                                      %WS_overlappedwindow,TO hDlg&
            CONTROL ADD LISTBOX, hDlg&,101,,5,5,180,35,%LBS_SORT OR %WS_VSCROLL OR %WS_TABSTOP, %WS_EX_CLIENTEDGE
            CONTROL ADD TEXTBOX, hDlg&,4000,"",5,40,180,50,%ES_MULTILINE OR %ES_AUTOVSCROLL _
                            OR %WS_VSCROLL OR %ES_WANTRETURN OR %WS_CHILD OR %WS_VISIBLE  OR %WS_TABSTOP, _
                %WS_EX_CLIENTEDGE
            CONTROL ADD TEXTBOX, hDlg&,3000,ctext$,5,100,180,30,%ES_MULTILINE OR %ES_AUTOVSCROLL _
                            OR %WS_VSCROLL OR %ES_WANTRETURN OR %WS_CHILD OR %WS_VISIBLE _
                             OR %WS_TABSTOP, _
                %WS_EX_CLIENTEDGE
            CONTROL ADD BUTTON, hDlg&, 1006, "SEND", 150,135,36, 16
            CONTROL ADD LABEL, hDlg&,1109, "Name:",  5, 135, 28, 11
            CONTROL ADD TEXTBOX,hDlg&,1110, "A",  42, 135, 44, 11
            DIALOG SHOW MODELESS hDlg&, CALL DlgProc()
          WHILE GetMessage(Msg, %NULL, 0, 0)
            TranslateMessage Msg
            DispatchMessage Msg
          WEND
        END FUNCTION ' (PBMAIN)
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        SUB LogRecvEvent (BYVAL Buffer AS STRING)
            LOCAL idx AS LONG
            Buffer = TIME$ + " - " + Buffer
            idx = SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))
            SendMessage hList, %LB_SETCURSEL, idx, 0
        END SUB
        SUB LogSendEvent (BYVAL Buffer AS STRING)
            LOCAL idx AS LONG
            Buffer = "Sent - "+TIME$ + " - " + Buffer
            idx = SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))
            SendMessage hList, %LB_SETCURSEL, idx, 0
        END SUB
        '------------------------------------------------------------------------------
        CALLBACK FUNCTION DlgProc () AS LONG
            LOCAL ctext$,cName$
            STATIC nServer   AS LONG
            STATIC hEcho     AS DWORD
            LOCAL  sBuffer   AS STRING
            LOCAL  sPacket   AS STRING
            LOCAL nSocket AS LONG
            LOCAL ip&,hostname$
            SELECT CASE CBMSG
        
            CASE %WM_INITDIALOG
                hList = GetDlgItem(CBHNDL, 101)
                nServer = FREEFILE
                TCP OPEN SERVER PORT 2999 AS nServer TIMEOUT 5000  '<---------- switch port for other inst
                IF ERR THEN
                    sBuffer = "Couldn't create socket!"
                ELSE
                    TCP NOTIFY nServer, ACCEPT TO CBHNDL AS %TCP_ACCEPT
                      HOST ADDR TO ip&
                      HOST NAME TO hostname$
                      sBuffer = "port: 2999 "+"ip: "+STR$(ip&)+"  "+hostname$  '<---------- switch port for other inst
                END IF
                LogRecvEvent sBuffer
                hEcho = %INVALID_SOCKET
                FUNCTION = 1
        
            CASE %TCP_ACCEPT
                SELECT CASE LOWRD(CBLPARAM)
                CASE %FD_ACCEPT
                    hEcho = FREEFILE
                    TCP ACCEPT nServer AS hEcho
                    TCP NOTIFY hEcho, RECV CLOSE TO CBHNDL AS %TCP_ECHO
                END SELECT
                FUNCTION = 1
        
            CASE %TCP_ECHO
                SELECT CASE LOWRD(CBLPARAM)
        
                CASE %FD_READ
                    IF hEcho <> %INVALID_SOCKET THEN
                        ' Perform a receive-loop until there is no data left (ie, the end of stream)
                        sBuffer = ""
                        sPacket = ""
        
                        DO
                          TCP RECV hEcho, 1024, sBuffer
                          sPacket = sPacket + sBuffer
                        LOOP UNTIL sBuffer = "" OR ISTRUE EOF(hEcho) OR ISTRUE ERR
        
                        ' Send it back!
                        IF LEN(sBuffer) THEN TCP SEND hEcho, sPacket + " -> Received Ok!"
                        LogRecvEvent  " Recv: (" + FORMAT$(LEN(sPacket)) + " bytes)"
                        sBuffer=sBuffer+$CRLF
                        CONTROL SEND CBHNDL,4000, %EM_REPLACESEL, 0, STRPTR(sBuffer)
                    ELSE
                        LogRecvEvent "* FD_READ Error!"
        
                    END IF
        
                CASE %FD_CLOSE
                    TCP CLOSE hEcho
                    hEcho = %INVALID_SOCKET
        
                END SELECT
                FUNCTION = 1
        
            CASE %WM_COMMAND
                SELECT CASE LOWRD(CBWPARAM)
        
        CASE 1006              'SEND
            TCP OPEN PORT 2998 AT $SERVER AS nSocket TIMEOUT 5000   '<---------- switch port for other inst
            IF ERR THEN
                MSGBOX "Error opening port: " + STR$(ERR)
                EXIT FUNCTION
            END IF
        
            IF LEN(COMMAND$) THEN
                TCP PRINT nSocket, COMMAND$;
            ELSE
                CONTROL GET TEXT CBHNDL,3000 TO ctext$
                CONTROL GET TEXT CBHNDL,1110 TO cName$
                ctext$=cName$+": "+ctext$'+$CRLF
                TCP PRINT nSocket, ctext$;
                CONTROL SET TEXT CBHNDL,3000, ""
                ctext$=ctext$+$CRLF
                CONTROL SEND CBHNDL,4000, %EM_REPLACESEL, 0, STRPTR(ctext$)
                LogRecvEvent " sent: (" + FORMAT$(LEN(ctext$)) + " bytes)"
            END IF
            ERRCLEAR
        
            DO
                TCP RECV nSocket, 1024, sBuffer
                sPacket = sPacket + sBuffer
            LOOP UNTIL sBuffer = "" OR ISTRUE EOF(nSocket) OR ISTRUE ERR
        
            IF ERR THEN MSGBOX "Error" + STR$(ERR)
            TCP CLOSE nSocket
                    FUNCTION = 1
                CASE 102
                    PostQuitMessage 0
                    EndDialog CBHNDL, 0
                    FUNCTION = 1
                END SELECT
        
            CASE %WM_DESTROY
                PostQuitMessage 0
                TCP CLOSE nServer
        
            CASE %WM_SYSCOMMAND
                SELECT CASE LOWRD(CBWPARAM)
        
                CASE %SC_CLOSE
                    SendMessage CBHNDL, %WM_COMMAND, 102, 0
                    FUNCTION = 1
                    EXIT FUNCTION
                END SELECT
            END SELECT
        END FUNCTION

        Code:
        #COMPILE EXE
        #DIM ALL
        #INCLUDE  "WIN32API.INC"
        #INCLUDE  "WS2_32.INC"
        
        %TCP_ACCEPT = %WM_USER + 4093
        %TCP_ECHO   = %WM_USER + 4094
        $SERVER = ""    '172.137.42.188"
        
        GLOBAL hList AS LONG
        DECLARE CALLBACK FUNCTION DlgProc() AS LONG
        '------------------------------------------------------------------------------
        FUNCTION PBMAIN
            LOCAL hDlg&, Msg AS tagMsg, ctext$
            ctext$="test"
            DIALOG NEW %HWND_DESKTOP, "Chat Works400:B",100,100,250,160, _
                                      %WS_overlappedwindow,TO hDlg&
            CONTROL ADD LISTBOX, hDlg&,101,,5,5,180,35,%LBS_SORT OR %WS_VSCROLL OR %WS_TABSTOP, %WS_EX_CLIENTEDGE
            CONTROL ADD TEXTBOX, hDlg&,4000,"",5,40,180,50,%ES_MULTILINE OR %ES_AUTOVSCROLL _
                            OR %WS_VSCROLL OR %ES_WANTRETURN OR %WS_CHILD OR %WS_VISIBLE  OR %WS_TABSTOP, _
                %WS_EX_CLIENTEDGE
            CONTROL ADD TEXTBOX, hDlg&,3000,ctext$,5,100,180,30,%ES_MULTILINE OR %ES_AUTOVSCROLL _
                            OR %WS_VSCROLL OR %ES_WANTRETURN OR %WS_CHILD OR %WS_VISIBLE _
                             OR %WS_TABSTOP, _
                %WS_EX_CLIENTEDGE
            CONTROL ADD BUTTON, hDlg&, 1006, "SEND", 150,135,36, 16
            CONTROL ADD LABEL, hDlg&,1109, "Name:",  5, 135, 28, 11
            CONTROL ADD TEXTBOX,hDlg&,1110, "B",  42, 135, 44, 11
            DIALOG SHOW MODELESS hDlg&, CALL DlgProc()
          WHILE GetMessage(Msg, %NULL, 0, 0)
            TranslateMessage Msg
            DispatchMessage Msg
          WEND
        END FUNCTION ' (PBMAIN)
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        SUB LogRecvEvent (BYVAL Buffer AS STRING)
            LOCAL idx AS LONG
            Buffer = TIME$ + " - " + Buffer
            idx = SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))
            SendMessage hList, %LB_SETCURSEL, idx, 0
        END SUB
        SUB LogSendEvent (BYVAL Buffer AS STRING)
            LOCAL idx AS LONG
            Buffer = "Sent - "+TIME$ + " - " + Buffer
            idx = SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))
            SendMessage hList, %LB_SETCURSEL, idx, 0
        END SUB
        '------------------------------------------------------------------------------
        CALLBACK FUNCTION DlgProc () AS LONG
            LOCAL ctext$,cName$
            STATIC nServer   AS LONG
            STATIC hEcho     AS DWORD
            LOCAL  sBuffer   AS STRING
            LOCAL  sPacket   AS STRING
            LOCAL nSocket AS LONG
            LOCAL ip&,hostname$
            SELECT CASE CBMSG
        
            CASE %WM_INITDIALOG
                hList = GetDlgItem(CBHNDL, 101)
                nServer = FREEFILE
                TCP OPEN SERVER PORT 2998 AS nServer TIMEOUT 5000  '<---------- switch port for other inst
                IF ERR THEN
                    sBuffer = "Couldn't create socket!"
                ELSE
                    TCP NOTIFY nServer, ACCEPT TO CBHNDL AS %TCP_ACCEPT
                      HOST ADDR TO ip&
                      HOST NAME TO hostname$
                      sBuffer = "port: 2998 "+"ip: "+STR$(ip&)+"  "+hostname$  '<---------- switch port for other inst
                END IF
                LogRecvEvent sBuffer
                hEcho = %INVALID_SOCKET
                FUNCTION = 1
        
            CASE %TCP_ACCEPT
                SELECT CASE LOWRD(CBLPARAM)
                CASE %FD_ACCEPT
                    hEcho = FREEFILE
                    TCP ACCEPT nServer AS hEcho
                    TCP NOTIFY hEcho, RECV CLOSE TO CBHNDL AS %TCP_ECHO
                END SELECT
                FUNCTION = 1
        
            CASE %TCP_ECHO
                SELECT CASE LOWRD(CBLPARAM)
        
                CASE %FD_READ
                    IF hEcho <> %INVALID_SOCKET THEN
                        ' Perform a receive-loop until there is no data left (ie, the end of stream)
                        sBuffer = ""
                        sPacket = ""
        
                        DO
                          TCP RECV hEcho, 1024, sBuffer
                          sPacket = sPacket + sBuffer
                        LOOP UNTIL sBuffer = "" OR ISTRUE EOF(hEcho) OR ISTRUE ERR
        
                        ' Send it back!
                        IF LEN(sBuffer) THEN TCP SEND hEcho, sPacket + " -> Received Ok!"
                        LogRecvEvent  " Recv: (" + FORMAT$(LEN(sPacket)) + " bytes)"
                        sBuffer=sBuffer+$CRLF
                        CONTROL SEND CBHNDL,4000, %EM_REPLACESEL, 0, STRPTR(sBuffer)
                    ELSE
                        LogRecvEvent "* FD_READ Error!"
        
                    END IF
        
                CASE %FD_CLOSE
                    TCP CLOSE hEcho
                    hEcho = %INVALID_SOCKET
        
                END SELECT
                FUNCTION = 1
        
            CASE %WM_COMMAND
                SELECT CASE LOWRD(CBWPARAM)
        
        CASE 1006              'SEND
            TCP OPEN PORT 2999 AT $SERVER AS nSocket TIMEOUT 5000   '<---------- switch port for other inst
            IF ERR THEN
                MSGBOX "Error opening port: " + STR$(ERR)
                EXIT FUNCTION
            END IF
        
            IF LEN(COMMAND$) THEN
                TCP PRINT nSocket, COMMAND$;
            ELSE
                CONTROL GET TEXT CBHNDL,3000 TO ctext$
                CONTROL GET TEXT CBHNDL,1110 TO cName$
                ctext$=cName$+": "+ctext$'+$CRLF
                TCP PRINT nSocket, ctext$;
                CONTROL SET TEXT CBHNDL,3000, ""
                ctext$=ctext$+$CRLF
                CONTROL SEND CBHNDL,4000, %EM_REPLACESEL, 0, STRPTR(ctext$)
                LogRecvEvent " sent: (" + FORMAT$(LEN(ctext$)) + " bytes)"
            END IF
            ERRCLEAR
        
            DO
                TCP RECV nSocket, 1024, sBuffer
                sPacket = sPacket + sBuffer
            LOOP UNTIL sBuffer = "" OR ISTRUE EOF(nSocket) OR ISTRUE ERR
        
            IF ERR THEN MSGBOX "Error" + STR$(ERR)
            TCP CLOSE nSocket
                    FUNCTION = 1
                CASE 102
                    PostQuitMessage 0
                    EndDialog CBHNDL, 0
                    FUNCTION = 1
                END SELECT
        
            CASE %WM_DESTROY
                PostQuitMessage 0
                TCP CLOSE nServer
        
            CASE %WM_SYSCOMMAND
                SELECT CASE LOWRD(CBWPARAM)
        
                CASE %SC_CLOSE
                    SendMessage CBHNDL, %WM_COMMAND, 102, 0
                    FUNCTION = 1
                    EXIT FUNCTION
                END SELECT
            END SELECT
        END FUNCTION

        Comment


        • #5
          maybe understand???

          I just changed my receive buffer size from,

          TCP RECV hEcho, 1024, sBuffer
          to,
          TCP RECV hEcho, 8192, sBuffer

          sent a 5500 byte file and the trailing 0 bytes msg went away

          Comment


          • #6
            Sorry, your demo does not send large packets.
            CMD shortcut to open any location:
            %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
            Change to run as administrator
            How long is an idea? Write it down.

            Comment


            • #7
              hmmm, ok maybe I'm confused,

              a packet is any group of transmission you want to send in, correct?

              it's up to you to define it's size, correct?

              if so, the demo is only sending a first packet of undefined size, correct?

              written for PBWin7 btw

              ?????

              Comment


              • #8
                Try sending 3000 bytes 10 times to your chat program.
                Just modify the number of attempts and the port number in your program to 999.
                CMD shortcut to open any location:
                %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
                Change to run as administrator
                How long is an idea? Write it down.

                Comment


                • #9
                  My new server handles 500 connections and I haven't been able to break it. Limitation: no packets over 1460-bytes. I'm still trying to figure it
                  out. I am stress testing. Sending once may work, but try 1000 times.
                  Last edited by Mike Doty; 5 Feb 2009, 02:02 AM.
                  CMD shortcut to open any location:
                  %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
                  Change to run as administrator
                  How long is an idea? Write it down.

                  Comment


                  • #10
                    ok

                    Comment


                    • #11
                      hehe, I'm sure this works!

                      tested on PBWin7.02


                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      #INCLUDE  "WIN32API.INC"
                      #INCLUDE  "WS2_32.INC"
                      
                      %TCP_ACCEPT = %WM_USER + 4093
                      %TCP_ECHO   = %WM_USER + 4094
                      $SERVER = ""
                      
                      GLOBAL hList AS LONG
                      DECLARE CALLBACK FUNCTION DlgProc() AS LONG
                      '------------------------------------------------------------------------------
                      FUNCTION PBMAIN
                          LOCAL hDlg&, Msg AS tagMsg, ctext$
                          ctext$="test"
                          DIALOG NEW %HWND_DESKTOP, "TCP Server",200,50,350,380, _
                                                    %WS_overlappedwindow,TO hDlg&
                          CONTROL ADD LISTBOX, hDlg&,101,,5,5,280,100,%LBS_SORT OR %WS_VSCROLL OR %WS_TABSTOP, %WS_EX_CLIENTEDGE
                      
                      
                          CONTROL ADD TEXTBOX, hDlg&,4000,"",5,110,280,250,%ES_MULTILINE OR %ES_AUTOVSCROLL _
                                          OR %WS_VSCROLL OR %ES_WANTRETURN OR %WS_CHILD OR %WS_VISIBLE  OR %WS_TABSTOP, _
                              %WS_EX_CLIENTEDGE
                      
                          DIALOG SHOW MODELESS hDlg&, CALL DlgProc()
                        WHILE GetMessage(Msg, %NULL, 0, 0)
                          TranslateMessage Msg
                          DispatchMessage Msg
                        WEND
                      END FUNCTION ' (PBMAIN)
                      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      SUB LogRecvEvent (BYVAL Buffer AS STRING)
                          LOCAL idx AS LONG
                          Buffer = "Recv - " + TIME$ + " - " + Buffer
                          idx = SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))
                          SendMessage hList, %LB_SETCURSEL, idx, 0
                      END SUB
                      SUB LogSendEvent (BYVAL Buffer AS STRING)
                          LOCAL idx AS LONG
                          Buffer = "Sent - "+TIME$ + " - " + Buffer
                          idx = SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))
                          SendMessage hList, %LB_SETCURSEL, idx, 0
                      END SUB
                      '------------------------------------------------------------------------------
                      CALLBACK FUNCTION DlgProc () AS LONG
                          LOCAL ctext$,cName$
                          STATIC nServer   AS LONG
                          STATIC hEcho     AS DWORD
                          LOCAL  sBuffer   AS STRING
                          LOCAL  sPacket   AS STRING
                          LOCAL nSocket AS LONG
                          LOCAL ip&,hostname$
                          SELECT CASE CBMSG
                      
                          CASE %WM_INITDIALOG
                              hList = GetDlgItem(CBHNDL, 101)
                              nServer = FREEFILE
                      
                              TCP OPEN SERVER PORT 999 AS nServer TIMEOUT 5000  '<---------- switch port for other inst
                              IF ERR THEN
                                  sBuffer = "Couldn't create socket!"
                              ELSE
                                  TCP NOTIFY nServer, ACCEPT TO CBHNDL AS %TCP_ACCEPT
                                    HOST ADDR TO ip&
                                    HOST NAME TO hostname$
                                    sBuffer = "port: 999 "+"ip: "+STR$(ip&)+"  "+hostname$  '<---------- switch port for other inst
                              END IF
                              LogRecvEvent sBuffer
                              hEcho = %INVALID_SOCKET
                              FUNCTION = 1
                      
                          CASE %TCP_ACCEPT
                              SELECT CASE LOWRD(CBLPARAM)
                              CASE %FD_ACCEPT
                                  hEcho = FREEFILE
                                  TCP ACCEPT nServer AS hEcho
                                  TCP NOTIFY hEcho, RECV CLOSE TO CBHNDL AS %TCP_ECHO
                              END SELECT
                              FUNCTION = 1
                      
                          CASE %TCP_ECHO
                              SELECT CASE LOWRD(CBLPARAM)
                      
                              CASE %FD_READ
                                  IF hEcho <> %INVALID_SOCKET THEN
                                      ' Perform a receive-loop until there is no data left (ie, the end of stream)
                                      sBuffer = ""
                                      sPacket = ""
                      
                                      DO
                                        TCP RECV hEcho,  4096, sBuffer
                      
                                      LOOP UNTIL sBuffer = "" OR ISTRUE EOF(hEcho) OR ISTRUE ERR
                      
                                      sPacket = sPacket + " -> Received Ok!"
                                      ' Send it back!
                                      IF LEN(sBuffer) THEN TCP SEND hEcho, sPacket
                                      LogSendEvent   FORMAT$(LEN(sPacket)) + " bytes)"
                                      LogRecvEvent   FORMAT$(LEN(sBuffer)) + " bytes)"
                                      sBuffer=sBuffer+$CRLF
                                      CONTROL SEND CBHNDL,4000, %EM_REPLACESEL, 0, STRPTR(sBuffer)
                      
                                  ELSE
                                      LogSendEvent "* FD_READ Error!"
                      
                                  END IF
                      
                              CASE %FD_CLOSE
                                  TCP CLOSE hEcho
                                  hEcho = %INVALID_SOCKET
                      
                              END SELECT
                              FUNCTION = 1
                      
                          CASE %WM_COMMAND
                              SELECT CASE LOWRD(CBWPARAM)
                      
                      
                              CASE 102
                                  PostQuitMessage 0
                                  EndDialog CBHNDL, 0
                                  FUNCTION = 1
                              END SELECT
                      
                          CASE %WM_DESTROY
                              PostQuitMessage 0
                              TCP CLOSE nServer
                      
                          CASE %WM_SYSCOMMAND
                              SELECT CASE LOWRD(CBWPARAM)
                      
                              CASE %SC_CLOSE
                                  SendMessage CBHNDL, %WM_COMMAND, 102, 0
                                  FUNCTION = 1
                                  EXIT FUNCTION
                              END SELECT
                          END SELECT
                      END FUNCTION
                      and,

                      Code:
                      #COMPILE EXE
                      #DIM ALL
                      #INCLUDE  "WIN32API.INC"
                      #INCLUDE  "WS2_32.INC"
                      
                      %TCP_ACCEPT = %WM_USER + 4093
                      %TCP_ECHO   = %WM_USER + 4094
                      $SERVER = ""
                      
                      GLOBAL hList AS LONG
                      DECLARE CALLBACK FUNCTION DlgProc() AS LONG
                      '------------------------------------------------------------------------------
                      FUNCTION PBMAIN
                          LOCAL hDlg&, Msg AS tagMsg, ctext$
                          ctext$="test"
                          DIALOG NEW %HWND_DESKTOP, "TCP Client",100,100,350,350, _
                                                    %WS_overlappedwindow,TO hDlg&
                          CONTROL ADD LISTBOX, hDlg&,101,,5,5,280,100,%LBS_SORT OR %WS_VSCROLL OR %WS_TABSTOP, %WS_EX_CLIENTEDGE
                      
                          CONTROL ADD TEXTBOX, hDlg&,4000,"",5,110,280,200,%ES_MULTILINE OR %ES_AUTOVSCROLL _
                                          OR %WS_VSCROLL OR %ES_WANTRETURN OR %WS_CHILD OR %WS_VISIBLE  OR %WS_TABSTOP, _
                              %WS_EX_CLIENTEDGE
                      
                      
                           CONTROL ADD BUTTON, hDlg&, 1006, "SEND 20 3k packets", 10,320,100, 16
                      
                          DIALOG SHOW MODELESS hDlg&, CALL DlgProc()
                        WHILE GetMessage(Msg, %NULL, 0, 0)
                          TranslateMessage Msg
                          DispatchMessage Msg
                        WEND
                      END FUNCTION ' (PBMAIN)
                      '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      SUB LogRecvEvent (BYVAL Buffer AS STRING)
                          LOCAL idx AS LONG
                          Buffer = "Recv - " + TIME$ + " - " + Buffer
                          idx = SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))
                          SendMessage hList, %LB_SETCURSEL, idx, 0
                      END SUB
                      SUB LogSendEvent (BYVAL Buffer AS STRING)
                          LOCAL idx AS LONG
                          Buffer = "Sent - "+TIME$ + " - " + Buffer
                          idx = SendMessage(hList, %LB_ADDSTRING, 0, STRPTR(Buffer))
                          SendMessage hList, %LB_SETCURSEL, idx, 0
                      END SUB
                      '------------------------------------------------------------------------------
                      CALLBACK FUNCTION DlgProc () AS LONG
                          LOCAL ctext$,cName$
                          STATIC nServer   AS LONG
                          STATIC hEcho     AS DWORD
                          LOCAL  sBuffer   AS STRING
                          LOCAL  rBuffer   AS STRING
                          LOCAL  sPacket   AS STRING
                          LOCAL  logdata   AS STRING
                      
                          STATIC  dPacket   AS STRING
                          LOCAL nSocket AS LONG
                          LOCAL ip&,hostname$, i&
                          SELECT CASE CBMSG
                                 CASE %WM_INITDIALOG
                               hList = GetDlgItem(CBHNDL, 101)
                              nServer = FREEFILE
                      
                             dPacket$=""
                              FOR i = 1 TO 30
                                  dPacket$=dPacket$ +"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
                              NEXT i
                      
                      
                      
                          CASE %WM_COMMAND
                              SELECT CASE LOWRD(CBWPARAM)
                      
                      CASE 1006              'SEND
                      
                      
                      
                      
                          TCP OPEN PORT 999 AT $SERVER AS nSocket TIMEOUT 5000   '<---------- switch port for other inst
                          IF ERR THEN
                              MSGBOX "Error opening port: " + STR$(ERR)
                              EXIT FUNCTION
                          END IF
                      
                          FOR i = 1 TO 100
                          IF LEN(COMMAND$) = 0 THEN
                              TCP PRINT nSocket, dPacket$;
                              LogSendEvent  FORMAT$(LEN(dPacket$)) + " bytes)"
                          ELSE
                              TCP PRINT nSocket, COMMAND$;
                          END IF
                      
                          DO
                              TCP RECV nSocket,  4096, rBuffer
                      
                                      CONTROL SEND CBHNDL,4000, %EM_REPLACESEL, 0, STRPTR(rBuffer$)
                                      LogRecvEvent FORMAT$(LEN(rBuffer$)) + " bytes)"
                                      
                          LOOP UNTIL rBuffer = "" OR ISTRUE EOF(nSocket) OR ISTRUE ERR
                          rBuffer = ""
                      
                          ERRCLEAR
                         NEXT i
                      
                      
                      
                          IF ERR THEN MSGBOX "Error" + STR$(ERR)
                          TCP CLOSE nSocket
                                  FUNCTION = 1
                              CASE 102
                                  PostQuitMessage 0
                                  EndDialog CBHNDL, 0
                                  FUNCTION = 1
                              END SELECT
                      
                          CASE %WM_DESTROY
                              PostQuitMessage 0
                              TCP CLOSE nServer
                      
                          CASE %WM_SYSCOMMAND
                              SELECT CASE LOWRD(CBWPARAM)
                      
                              CASE %SC_CLOSE
                                  SendMessage CBHNDL, %WM_COMMAND, 102, 0
                                  FUNCTION = 1
                                  EXIT FUNCTION
                              END SELECT
                          END SELECT
                      END FUNCTION
                      Last edited by Brad D Byrne; 5 Feb 2009, 01:34 PM. Reason: updated code

                      Comment


                      • #12
                        Multi-threaded stress test of server

                        I will try to find out more on this 1460 byte packet length, later.
                        If PB Echo server is running this will test it to the max.
                        Code:
                        #COMPILE EXE 'Echo client on steroids to test Echo Server
                        'Having problem with packets over 1460 bytes.
                         
                        #DIM ALL
                         
                        %MaximumPacket1460 = 1460
                        $SERVER = ""
                         
                        FUNCTION PBMAIN () AS LONG
                           LOCAL ConnectionNumber AS LONG
                           LOCAL result AS LONG
                           REDIM Threads(500) AS LONG
                           FOR ConnectionNumber = 1 TO 10  'maximum UBOUND(Threads)
                             THREAD CREATE TEST(ConnectionNumber) TO Threads(ConnectionNumber)
                             IF Threads(ConnectionNumber) = 0 THEN
                                ? "Unable to create thread" + STR$(ConnectionNumber)
                             ELSE
                               THREAD CLOSE Threads(ConnectionNumber) TO result
                             END IF
                             SLEEP 250
                           NEXT
                           DO WHILE THREADCOUNT > 1:SLEEP 100:LOOP
                           ? "Threads finished"
                        END FUNCTION
                         
                        THREAD FUNCTION TEST(BYVAL x AS LONG) AS LONG
                           LOCAL Counter AS LONG
                           LOCAL PacketLength  AS LONG     'don't exceed 1460 ????
                           LOCAL nSocket AS LONG
                           LOCAL sBuffer AS STRING
                           LOCAL sPacket AS STRING
                           nSocket = FREEFILE
                           TCP OPEN PORT 999 AT $SERVER AS nSocket TIMEOUT 10000   'your IP 
                           IF ERR THEN ? "Error opening port: " + STR$(ERR):EXIT FUNCTION
                        FOR Counter = 1 TO 1000
                        'counter 1000 and PackLength 1000 = million bytes sent to and fro
                            'PacketLength = RND(1, %MaximumPacket1460)  ' >1460 still testing!!!
                            PacketLength = 1000
                            TCP SEND nSocket, STRING$(PacketLength,"X")
                            ERRCLEAR
                            sPacket = ""
                            sBuffer = ""
                            DO
                                TCP RECV nSocket, 8192, sBuffer
                                sPacket = sPacket + sBuffer
                            LOOP UNTIL sBuffer = "" OR ISTRUE EOF(nSocket) OR ISTRUE ERR
                            IF LEN(sPacket) <> PacketLength THEN
                               ? "Failed on attempt" + STR$(Counter) + " packet returned" + STR$(LEN(sPacket))
                               EXIT FOR
                            END IF
                        NEXT
                        TCP CLOSE nSocket
                        END FUNCTION
                        Last edited by Mike Doty; 5 Feb 2009, 06:27 AM.
                        CMD shortcut to open any location:
                        %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
                        Change to run as administrator
                        How long is an idea? Write it down.

                        Comment


                        • #13
                          Maybe this will help explain it:
                          http://en.wikipedia.org/wiki/Maximum_transmission_unit
                          http://help.expedient.com/broadband/mtu_ping_test.shtml

                          Paul.

                          Comment


                          • #14
                            For example, a 1500 byte packet, the largest allowed by Ethernet at the network layer (and hence most of the Internet), would tie up a 14.4k modem for about one second.
                            Thanks, much! I need to get some shut-eye. I'll read completely later today.

                            If this is a limit, it would be a great addition to the TCP RECV command documentation.
                            Last edited by Mike Doty; 5 Feb 2009, 06:49 AM.
                            CMD shortcut to open any location:
                            %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
                            Change to run as administrator
                            How long is an idea? Write it down.

                            Comment


                            • #15
                              Something sounds wrong here. At the layer level PB deals with the TCP protocol then the packet size (MTU) is irrelevent as winsock will fragment it for you. For a LAN you can change the maximum size of a packet in the registry though it needs to be done on all the computers on the network to be of any use. Knowing the packet size or changing it can help in transfer speed but that is all, ie matching your data transmissions the the data allowable in a packet means that no fragmentation occurs. This helps transmission speed in two ways, it helps by taking a load off winsock and secondly but more important can reduce the number of packets. Ethernet is a collision detecting protocol so the less packets the less chance of a collision. If a collision occurs ie two computers trying to transmit a packet at the same time then then both back off and wait a random amount of time before retrying so the original time slot is wasted.
                              PS if you are running both the server and client on the same computer you should be using the loopback address 127.0.0.1 not the IP addres of the computers NIC
                              Last edited by John Petty; 5 Feb 2009, 08:33 AM.

                              Comment


                              • #16
                                FWIW, Frame-sizes on a LAN are a waste of time. Leave them at the default and look at other areas if you are trying to increase performance. Changing TCP settings on a LAN will generally be measured in billionths of nanoseconds...not worth the time.

                                For a WAN, *IF* you control both (all) end points, you *could* increase performance a tad....at the risk of clobbering other applications.

                                TCP/IP is not akin to "open the frame size, more data will gleefully flow through". There is a lot more to it. Sliding windows sizes and timing will give you better throughput increases if you want to get right down to it.

                                Ethernet is a collision detecting protocol so the less packets the less chance of a collision. If a collision occurs ie two computers trying to transmit a packet at the same time then then both back off and wait a random amount of time before retrying so the original time slot is wasted.
                                True, but in a properly configured switched network, collision domains are nearly eliminated reducing re-transmissions to almost zero.
                                Software makes Hardware Happen

                                Comment


                                • #17
                                  Joe
                                  Totally agree, in fact if you make the packet too large some switches will consider it as a "jabber" and close it off. His problem shouldn't have anything to do with packet size which is at the lowest level in the protocol and without changing registry entries he should not even be considering it.
                                  It may be as simple as some chr$(0) in his strings, I think he is looking in the wrong areas.
                                  John

                                  Comment


                                  • #18
                                    hmmm, well maybe I really have no idea what's going on, because I think my eariler demos work, I cleaned them up & made them clearer in the earlier post #11,

                                    here's a screen shot in action, http://www.intelifaqs.com/images/tcp.png

                                    Mike, I believe that your server code must not be sending back any reply which would mess it up????

                                    am I all wrong about this????
                                    Last edited by Brad D Byrne; 5 Feb 2009, 01:37 PM.

                                    Comment


                                    • #19
                                      I'm back to testing, right now.
                                      I will use multiple machines and see what is causing this data loss.
                                      CMD shortcut to open any location:
                                      %windir%\system32\cmd.exe /k " cd\ & x: & cd x:\xxxx
                                      Change to run as administrator
                                      How long is an idea? Write it down.

                                      Comment


                                      • #20
                                        hmmm, just reread John & Joe's posts,

                                        makes sense to me

                                        Comment

                                        Working...
                                        X