Winsock what did I miss?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Henning

    Winsock what did I miss?

    Hi grp!
    Trying to receive a udp msg in vb6, but it shows only zeros. What have I
    missed?

    /Henning

    --
    Time is present only to prevent everything from happening at once.
    Still it seems that everything happens at once.
    Then there must be a bug in time.
    To find the bug in time, isn't that what we all hope for.


  • Henning

    #2
    SV: Winsock what did I miss?

    ;( as usual I "forgot" to attach the code ;(
    Private Sub Wsock_DataArriv al(ByVal bytesTotal As Long)
    Dim byteData(256) As Byte
    Dim i As Integer
    Text4.Text = bytesTotal
    Text3.Text = ""
    Wsock.GetData byteData(), vbArray + vbByte, bytesTotal
    For i = 0 To bytesTotal - 1
    Text3.Text = Text3.Text + Hex$(byteData(i ))
    Next
    End Sub
    /Henning
    "Henning" <computer_hero@ coldmail.com> skrev i meddelandet
    news:41b0c1f0$0 $91256$57c3e1d3 @news3.bahnhof. se...[color=blue]
    > Hi grp!
    > Trying to receive a udp msg in vb6, but it shows only zeros. What have I
    > missed?
    >
    > /Henning
    >
    > --
    > Time is present only to prevent everything from happening at once.
    > Still it seems that everything happens at once.
    > Then there must be a bug in time.
    > To find the bug in time, isn't that what we all hope for.
    >
    >[/color]


    Comment

    • Shell

      #3
      Re: Winsock what did I miss?

      In responce to the post:
      On Fri, 3 Dec 2004 20:47:07 +0100, "Henning"
      <computer_hero@ coldmail.com> stated...and I replied:
      [color=blue]
      >Hi grp!
      >Trying to receive a udp msg in vb6, but it shows only zeros. What have I
      >missed?
      >
      >/Henning[/color]

      Did you send a msg? <g>

      see next post
      Shell
      -

      Into computers since 1972.
      WARNING! Information and e-mail addresses contained herein, are for personal use only. By entering this site, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via direct mail, electronic mail, or by telephone. Violators will be dealt with accordingly.
      -

      Comment

      • Shell

        #4
        Re: SV: Winsock what did I miss?

        In responce to the post:
        On Fri, 3 Dec 2004 20:51:10 +0100, "Henning"
        <computer_hero@ coldmail.com> stated...and I replied:
        [color=blue]
        >;( as usual I "forgot" to attach the code ;(
        >Private Sub Wsock_DataArriv al(ByVal bytesTotal As Long)
        > Dim byteData(256) As Byte[/color]
        ^^^
        this would be 0 to 256...are you sure you don't want 256 as the
        amount? (e.g. 0 to 255?)
        [color=blue]
        > Dim i As Integer
        > Text4.Text = bytesTotal
        > Text3.Text = ""[/color]
        ^^^
        this would clear your receiving field each time the DataArrival event
        fires
        [color=blue]
        > Wsock.GetData byteData(), vbArray + vbByte, bytesTotal
        > For i = 0 To bytesTotal - 1
        > Text3.Text = Text3.Text + Hex$(byteData(i ))
        > Next
        >End Sub[/color]

        Do you know, in advance, the size of the data packet you're receiving?
        If so, you can truncate the excess data...which is probably what is
        clearing and zeroing your receiving field at the end of the
        transmission.

        Shell
        -

        Into computers since 1972.
        WARNING! Information and e-mail addresses contained herein, are for personal use only. By entering this site, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via direct mail, electronic mail, or by telephone. Violators will be dealt with accordingly.
        -

        Comment

        • Henning

          #5
          SV: SV: Winsock what did I miss?

          Jepp, I did send ;)
          The Sniffer told the package is ok
          When receiving to a string, it works.
          So, the quiz stands. What have I missed when trying the byte array. Data in
          pack is binary.
          And yes, I know the package size. It comes from a standalone mpu project,
          sending status changes of 8-bit ports. The 256 was just lazy ;) pkg size = 9
          bytes + header.
          /Henning

          "Shell" <___computerNOS PAMconsultant@m indspring.com__ _> skrev i meddelandet
          news:jhp1r0p803 45odq53jaal69ss 2id0a5r79@4ax.c om...[color=blue]
          > In responce to the post:
          > On Fri, 3 Dec 2004 20:51:10 +0100, "Henning"
          > <computer_hero@ coldmail.com> stated...and I replied:
          >[color=green]
          > >;( as usual I "forgot" to attach the code ;(
          > >Private Sub Wsock_DataArriv al(ByVal bytesTotal As Long)
          > > Dim byteData(256) As Byte[/color]
          > ^^^
          > this would be 0 to 256...are you sure you don't want 256 as the
          > amount? (e.g. 0 to 255?)
          >[color=green]
          > > Dim i As Integer
          > > Text4.Text = bytesTotal
          > > Text3.Text = ""[/color]
          > ^^^
          > this would clear your receiving field each time the DataArrival event
          > fires
          >[color=green]
          > > Wsock.GetData byteData(), vbArray + vbByte, bytesTotal
          > > For i = 0 To bytesTotal - 1
          > > Text3.Text = Text3.Text + Hex$(byteData(i ))
          > > Next
          > >End Sub[/color]
          >
          > Do you know, in advance, the size of the data packet you're receiving?
          > If so, you can truncate the excess data...which is probably what is
          > clearing and zeroing your receiving field at the end of the
          > transmission.
          >
          > Shell
          > -
          > http://drshell.home.mindspring.com/
          > Into computers since 1972.
          > WARNING! Information and e-mail addresses contained herein, are for[/color]
          personal use only. By entering this site, you agree that you will use this
          data only for lawful purposes and that, under no circumstances will you use
          this data to: allow, enable, or otherwise support the transmission of mass
          unsolicited, commercial advertising or solicitations via direct mail,
          electronic mail, or by telephone. Violators will be dealt with accordingly.[color=blue]
          > -[/color]


          Comment

          • Steve Gerrard

            #6
            Re: SV: Winsock what did I miss?


            "Henning" <computer_hero@ coldmail.com> wrote in message
            news:41b105e2$0 $91271$57c3e1d3 @news3.bahnhof. se...
            | Jepp, I did send ;)
            | The Sniffer told the package is ok
            | When receiving to a string, it works.
            | So, the quiz stands. What have I missed when trying the byte array.
            Data in
            | pack is binary.

            "Henning" <computer_hero@ coldmail.com> wrote in message
            news:41b0c2e2$0 $91256$57c3e1d3 @news3.bahnhof. se...

            | Private Sub Wsock_DataArriv al(ByVal bytesTotal As Long)
            | Dim byteData(256) As Byte

            | Wsock.GetData byteData(), vbArray + vbByte, bytesTotal

            I suspect that GetData is expecting a dynamic array, which it can resize
            to fit the data. So just doing
            Dim byteData() As Byte
            might do it. If not, then it might be expecting vbArray + vbByte to mean
            a variant containing a byte array, so
            Dim byteData As Variant
            might work.


            Comment

            • Shell

              #7
              Re: SV: Winsock what did I miss?

              In responce to the post:
              On Fri, 3 Dec 2004 18:13:28 -0800, "Steve Gerrard"
              <mynamehere@com cast.net> stated...and I replied:
              [color=blue]
              >
              >"Henning" <computer_hero@ coldmail.com> wrote in message
              >news:41b105e2$ 0$91271$57c3e1d 3@news3.bahnhof .se...
              >| Jepp, I did send ;)
              >| The Sniffer told the package is ok
              >| When receiving to a string, it works.
              >| So, the quiz stands. What have I missed when trying the byte array.
              >Data in
              >| pack is binary.
              >
              >"Henning" <computer_hero@ coldmail.com> wrote in message
              >news:41b0c2e2$ 0$91256$57c3e1d 3@news3.bahnhof .se...
              >
              >| Private Sub Wsock_DataArriv al(ByVal bytesTotal As Long)
              >| Dim byteData(256) As Byte
              >
              >| Wsock.GetData byteData(), vbArray + vbByte, bytesTotal
              >
              >I suspect that GetData is expecting a dynamic array, which it can resize
              >to fit the data. So just doing
              > Dim byteData() As Byte
              >might do it. If not, then it might be expecting vbArray + vbByte to mean
              >a variant containing a byte array, so
              > Dim byteData As Variant
              >might work.
              >[/color]
              No sir, the GetData is somewhat like the Get/Input statements. They
              require "sizing" to the amount of data to be received, and a ByteArray
              is just fine for this purpose.

              Shell
              -

              Into computers since 1972.
              WARNING! Information and e-mail addresses contained herein, are for personal use only. By entering this site, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via direct mail, electronic mail, or by telephone. Violators will be dealt with accordingly.
              -

              Comment

              • Shell

                #8
                Re: SV: SV: Winsock what did I miss?

                In responce to the post:
                On Sat, 4 Dec 2004 01:37:03 +0100, "Henning"
                <computer_hero@ coldmail.com> stated...and I replied:
                [color=blue]
                >Jepp, I did send ;)
                >The Sniffer told the package is ok
                >When receiving to a string, it works.
                >So, the quiz stands. What have I missed when trying the byte array. Data in
                >pack is binary.
                >And yes, I know the package size. It comes from a standalone mpu project,
                >sending status changes of 8-bit ports. The 256 was just lazy ;) pkg size = 9
                >bytes + header.
                >/Henning
                >[/color]

                The DataArrival event fires one to many times for each transmission.
                Even for a small packet like 9 bytes you could still be getting a
                second firing of the event, whereby the receiving field would be
                cleared, as well as the byte array being overlayed each time you
                GetData.

                I would bet the DataArrival event fires more than once.
                If you change the code to allow for multiple entry of the DataArrival
                event, you will see results.

                Shell
                -

                Into computers since 1972.
                WARNING! Information and e-mail addresses contained herein, are for personal use only. By entering this site, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via direct mail, electronic mail, or by telephone. Violators will be dealt with accordingly.
                -

                Comment

                • Steve Gerrard

                  #9
                  Re: SV: Winsock what did I miss?


                  "Shell" <___computerNOS PAMconsultant@m indspring.com__ _> wrote in message
                  news:oia4r0diru alqagflt1bm9ijv i9spdjvn8@4ax.c om...
                  | >| When receiving to a string, it works.
                  | >| So, the quiz stands. What have I missed when trying the byte array.

                  | >| Private Sub Wsock_DataArriv al(ByVal bytesTotal As Long)
                  | >| Dim byteData(256) As Byte
                  | >

                  | >I suspect that GetData is expecting a dynamic array, which it can
                  resize
                  | >to fit the data. So just doing
                  | > Dim byteData() As Byte
                  | >might do it.

                  | No sir, the GetData is somewhat like the Get/Input statements. They
                  | require "sizing" to the amount of data to be received, and a ByteArray
                  | is just fine for this purpose.
                  |

                  Good theory, but in fact incorrect. The examples in MSDN use unsized
                  strings, for instance, to receive text data, which gives a hint.

                  The following does work for receiving 4 bytes of data:

                  Private Sub Winsock3_DataAr rival(ByVal bytesTotal As Long)
                  Dim bytes() As Byte
                  Dim n As Integer

                  Winsock3.GetDat a bytes, vbArray + vbByte
                  For n = LBound(bytes) To UBound(bytes)
                  Debug.Print n, bytes(n)
                  Next n

                  End Sub

                  If you replace the Dim statement with
                  Dim bytes(0 to 3) As Byte

                  the bytes will remain all zero.



                  Comment

                  • Henning

                    #10
                    SV: SV: Winsock what did I miss?

                    Anyone to bet a dollar on Steve?
                    He is right!
                    When I saw the reply, I simply hit myself hard!
                    Thx Steve for pointing that out, it works like a dream now!
                    Thx again
                    /Henning (in computers since 1979)

                    "Steve Gerrard" <mynamehere@com cast.net> skrev i meddelandet
                    news:9KadnQ1S6o shpi_cRVn-2Q@comcast.com. ..[color=blue]
                    >
                    > "Shell" <___computerNOS PAMconsultant@m indspring.com__ _> wrote in message
                    > news:oia4r0diru alqagflt1bm9ijv i9spdjvn8@4ax.c om...
                    > | >| When receiving to a string, it works.
                    > | >| So, the quiz stands. What have I missed when trying the byte array.
                    >
                    > | >| Private Sub Wsock_DataArriv al(ByVal bytesTotal As Long)
                    > | >| Dim byteData(256) As Byte
                    > | >
                    >
                    > | >I suspect that GetData is expecting a dynamic array, which it can
                    > resize
                    > | >to fit the data. So just doing
                    > | > Dim byteData() As Byte
                    > | >might do it.
                    >
                    > | No sir, the GetData is somewhat like the Get/Input statements. They
                    > | require "sizing" to the amount of data to be received, and a ByteArray
                    > | is just fine for this purpose.
                    > |
                    >
                    > Good theory, but in fact incorrect. The examples in MSDN use unsized
                    > strings, for instance, to receive text data, which gives a hint.
                    >
                    > The following does work for receiving 4 bytes of data:
                    >
                    > Private Sub Winsock3_DataAr rival(ByVal bytesTotal As Long)
                    > Dim bytes() As Byte
                    > Dim n As Integer
                    >
                    > Winsock3.GetDat a bytes, vbArray + vbByte
                    > For n = LBound(bytes) To UBound(bytes)
                    > Debug.Print n, bytes(n)
                    > Next n
                    >
                    > End Sub
                    >
                    > If you replace the Dim statement with
                    > Dim bytes(0 to 3) As Byte
                    >
                    > the bytes will remain all zero.
                    >
                    >
                    >[/color]


                    Comment

                    • Shell

                      #11
                      Re: SV: Winsock what did I miss?

                      In responce to the post:
                      On Sat, 4 Dec 2004 14:35:41 -0800, "Steve Gerrard"
                      <mynamehere@com cast.net> stated...and I replied:
                      [color=blue]
                      >
                      >Good theory, but in fact incorrect. The examples in MSDN use unsized
                      >strings, for instance, to receive text data, which gives a hint.
                      >
                      >The following does work for receiving 4 bytes of data:
                      >
                      >Private Sub Winsock3_DataAr rival(ByVal bytesTotal As Long)
                      > Dim bytes() As Byte
                      > Dim n As Integer
                      >
                      > Winsock3.GetDat a bytes, vbArray + vbByte
                      > For n = LBound(bytes) To UBound(bytes)
                      > Debug.Print n, bytes(n)
                      > Next n
                      >
                      >End Sub
                      >
                      >If you replace the Dim statement with
                      > Dim bytes(0 to 3) As Byte
                      >
                      >the bytes will remain all zero.
                      >[/color]

                      Duh (to myself), you are in fact right. It's been over 3 years since
                      I programmed with the winsock control. I also remember that the
                      GetData function does not always get ALL the data. It, at times, must
                      be called many times to receive the full data stream. In fact, I've
                      had it called thousands of times to pass large files, with DoEvents
                      stuffed in to avoid the potential timeout problems.

                      Regards,
                      Shell
                      -

                      Into computers since 1972.
                      WARNING! Information and e-mail addresses contained herein, are for personal use only. By entering this site, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via direct mail, electronic mail, or by telephone. Violators will be dealt with accordingly.
                      -

                      Comment

                      • Shell

                        #12
                        Re: SV: SV: Winsock what did I miss?

                        In responce to the post:
                        On Sun, 5 Dec 2004 01:32:08 +0100, "Henning"
                        <computer_hero@ coldmail.com> stated...and I replied:
                        [color=blue]
                        >Anyone to bet a dollar on Steve?
                        >He is right!
                        >When I saw the reply, I simply hit myself hard!
                        >Thx Steve for pointing that out, it works like a dream now!
                        >Thx again
                        >/Henning (in computers since 1979)
                        >[/color]

                        Haha!! No fair, you alread knew the outcome before you asked for the
                        bet!

                        Shell
                        -

                        Into computers since 1972.
                        WARNING! Information and e-mail addresses contained herein, are for personal use only. By entering this site, you agree that you will use this data only for lawful purposes and that, under no circumstances will you use this data to: allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via direct mail, electronic mail, or by telephone. Violators will be dealt with accordingly.
                        -

                        Comment

                        • Steve Gerrard

                          #13
                          Re: SV: Winsock what did I miss?


                          "Shell" <___computerNOS PAMconsultant@m indspring.com__ _> wrote in message
                          news:rp67r0lehr hhmi6vd7crshgjp o9o3c8jn8@4ax.c om...
                          |
                          | Duh (to myself), you are in fact right. It's been over 3 years since
                          | I programmed with the winsock control. I also remember that the
                          | GetData function does not always get ALL the data. It, at times, must
                          | be called many times to receive the full data stream. In fact, I've
                          | had it called thousands of times to pass large files, with DoEvents
                          | stuffed in to avoid the potential timeout problems.
                          |
                          | Regards,
                          | Shell
                          | -

                          Yes, DataArrival may occur multiple times for a large transfer, and you
                          get no indication of the total size coming at you. I think the packet
                          size is basically whatever is used by the network. I seem to remember
                          sending a "header" that indicated the total transfer size, so the
                          receiving end could process the stream appropriately.


                          Comment

                          Working...