473,378 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.
Jul 17 '05 #1
12 8697
;( as usual I "forgot" to attach the code ;(
Private Sub Wsock_DataArrival(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" <co***********@coldmail.com> skrev i meddelandet
news:41***********************@news3.bahnhof.se...
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.

Jul 17 '05 #2
In responce to the post:
On Fri, 3 Dec 2004 20:47:07 +0100, "Henning"
<co***********@coldmail.com> stated...and I replied:
Hi grp!
Trying to receive a udp msg in vb6, but it shows only zeros. What have I
missed?

/Henning


Did you send a msg? <g>

see next post
Shell
-
http://drshell.home.mindspring.com/
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.
-
Jul 17 '05 #3
In responce to the post:
On Fri, 3 Dec 2004 20:51:10 +0100, "Henning"
<co***********@coldmail.com> stated...and I replied:
;( as usual I "forgot" to attach the code ;(
Private Sub Wsock_DataArrival(ByVal bytesTotal As Long)
Dim byteData(256) As Byte ^^^
this would be 0 to 256...are you sure you don't want 256 as the
amount? (e.g. 0 to 255?)
Dim i As Integer
Text4.Text = bytesTotal
Text3.Text = "" ^^^
this would clear your receiving field each time the DataArrival event
fires
Wsock.GetData byteData(), vbArray + vbByte, bytesTotal
For i = 0 To bytesTotal - 1
Text3.Text = Text3.Text + Hex$(byteData(i))
Next
End Sub


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 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.
-
Jul 17 '05 #4
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" <__*************************@mindspring.com___> skrev i meddelandet
news:jh********************************@4ax.com...
In responce to the post:
On Fri, 3 Dec 2004 20:51:10 +0100, "Henning"
<co***********@coldmail.com> stated...and I replied:
;( as usual I "forgot" to attach the code ;(
Private Sub Wsock_DataArrival(ByVal bytesTotal As Long)
Dim byteData(256) As Byte ^^^
this would be 0 to 256...are you sure you don't want 256 as the
amount? (e.g. 0 to 255?)
Dim i As Integer
Text4.Text = bytesTotal
Text3.Text = ""

^^^
this would clear your receiving field each time the DataArrival event
fires
Wsock.GetData byteData(), vbArray + vbByte, bytesTotal
For i = 0 To bytesTotal - 1
Text3.Text = Text3.Text + Hex$(byteData(i))
Next
End Sub


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

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. -

Jul 17 '05 #5

"Henning" <co***********@coldmail.com> wrote in message
news:41***********************@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" <co***********@coldmail.com> wrote in message
news:41***********************@news3.bahnhof.se...

| Private Sub Wsock_DataArrival(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.
Jul 17 '05 #6
In responce to the post:
On Fri, 3 Dec 2004 18:13:28 -0800, "Steve Gerrard"
<my********@comcast.net> stated...and I replied:

"Henning" <co***********@coldmail.com> wrote in message
news:41***********************@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" <co***********@coldmail.com> wrote in message
news:41***********************@news3.bahnhof.se.. .

| Private Sub Wsock_DataArrival(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.

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
-
http://drshell.home.mindspring.com/
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.
-
Jul 17 '05 #7
In responce to the post:
On Sat, 4 Dec 2004 01:37:03 +0100, "Henning"
<co***********@coldmail.com> stated...and I replied:
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


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
-
http://drshell.home.mindspring.com/
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.
-
Jul 17 '05 #8

"Shell" <__*************************@mindspring.com___> wrote in message
news:oi********************************@4ax.com...
| >| When receiving to a string, it works.
| >| So, the quiz stands. What have I missed when trying the byte array.

| >| Private Sub Wsock_DataArrival(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_DataArrival(ByVal bytesTotal As Long)
Dim bytes() As Byte
Dim n As Integer

Winsock3.GetData 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.

Jul 17 '05 #9
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" <my********@comcast.net> skrev i meddelandet
news:9K********************@comcast.com...

"Shell" <__*************************@mindspring.com___> wrote in message
news:oi********************************@4ax.com...
| >| When receiving to a string, it works.
| >| So, the quiz stands. What have I missed when trying the byte array.

| >| Private Sub Wsock_DataArrival(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_DataArrival(ByVal bytesTotal As Long)
Dim bytes() As Byte
Dim n As Integer

Winsock3.GetData 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.

Jul 17 '05 #10
In responce to the post:
On Sat, 4 Dec 2004 14:35:41 -0800, "Steve Gerrard"
<my********@comcast.net> stated...and I replied:

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_DataArrival(ByVal bytesTotal As Long)
Dim bytes() As Byte
Dim n As Integer

Winsock3.GetData 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.


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
-
http://drshell.home.mindspring.com/
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.
-
Jul 17 '05 #11
In responce to the post:
On Sun, 5 Dec 2004 01:32:08 +0100, "Henning"
<co***********@coldmail.com> stated...and I replied:
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)


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

Shell
-
http://drshell.home.mindspring.com/
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.
-
Jul 17 '05 #12

"Shell" <__*************************@mindspring.com___> wrote in message
news:rp********************************@4ax.com...
|
| 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.
Jul 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Niels Borg | last post by:
Hi, I'm writing app where I use WinSock, but I have experienced a problem. WinSock only sends the data after finishing the calling sub/function. Can I force WinSock immediately as I need to send...
3
by: Bill | last post by:
When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...). Why doesn't this work, and is there a work...
1
by: Yu Chai | last post by:
Hi guys, I created a ASP page that 1. users can run when WinSock proxy are using (ie's one is unchecked) 2. users can't run when WinSock proxy are using (ie's one is checked) 3. users can't run...
7
by: Nadav | last post by:
Hi I am writing some kind of a storage system that have to deal with large amounts of data passing over the net, Now, I Wonder... traditional programming would use win32 Winsock DLL as the means...
3
by: John | last post by:
Hello, I currently have Visual Basic .NET 2003 Standard Edition. I would like to develop a standard exe which should use the Winsock Control for VB.NET. I found some tutorials about it, started...
5
by: kc | last post by:
Hi Just upgrading a app from VB6 to VB.Net. All is going well apart from the Winsock control. The first thing we notice is that there does not appear to be a .Net version (please correct me if...
1
by: Nicolas Ghesquiere | last post by:
Hello I have a problem with my current program. The meaning of the program is to allow users to login to a server to allow them to access the internet. My program communicates with a MS isa...
4
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working,...
3
AaronL
by: AaronL | last post by:
Hello, I am currently working on a project that has me in sort of a bind. What I want to do is retrieve web pages from the internet, and strip them down to just text. I'll get using Regular...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.