winsock control
Hello,
maybe anybody has a quick solution to my problem.
In my application I get binary data which I read in with the winsock control. Here the code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim i As Integer
Dim Data() As Byte
'Winsock1.GetData Data ,vbByte //This line works in VB6
Data = Winsock1.GetData
For i = 0 To (UBound(Data))
ReDim Preserve Datax(DataxCount)
Datax(DataxCount) = Data(i)
DataxCount = DataxCount + 1
Next i
End Sub
In VB6 it is working fine. But with jabaco, bytes with a value bigger than 127 get lost. For example receiving a byte with the value 128 I later find 63 in the variable Datax. I am unable to find the reason. Has anybody an idea ?
Could anybody give ma a short example how to use the java socket in jabaco ? Maybe I can do my application that way.
Thanks a lot in advance
Vicente
maybe anybody has a quick solution to my problem.
In my application I get binary data which I read in with the winsock control. Here the code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim i As Integer
Dim Data() As Byte
'Winsock1.GetData Data ,vbByte //This line works in VB6
Data = Winsock1.GetData
For i = 0 To (UBound(Data))
ReDim Preserve Datax(DataxCount)
Datax(DataxCount) = Data(i)
DataxCount = DataxCount + 1
Next i
End Sub
In VB6 it is working fine. But with jabaco, bytes with a value bigger than 127 get lost. For example receiving a byte with the value 128 I later find 63 in the variable Datax. I am unable to find the reason. Has anybody an idea ?
Could anybody give ma a short example how to use the java socket in jabaco ? Maybe I can do my application that way.
Thanks a lot in advance
Vicente
Hi,
in your code, neither Datax nor DataxCount are defined. They may be defined elsewhere?
Add "Option Explicit" as first line of your source to avoid definition errors.
The next step to pin-down your problem could be to de-compile the Java class generated by Jabaco.
Search the forum for "jad" to get to know hints in this direction.
It might be that there is some type conversion error which chops off the most-significant bit of the data bytes.
Please post the complete code, if you need more help.
Success!
A1880
in your code, neither Datax nor DataxCount are defined. They may be defined elsewhere?
Add "Option Explicit" as first line of your source to avoid definition errors.
The next step to pin-down your problem could be to de-compile the Java class generated by Jabaco.
Search the forum for "jad" to get to know hints in this direction.
It might be that there is some type conversion error which chops off the most-significant bit of the data bytes.
Please post the complete code, if you need more help.
Success!
A1880
Server Client
Thank you for your comments so far, A1880.
Maybe you or anybody else has time to try my little server client application. The client sends a complete range of charcters to the server. As you will notice, the strange thing is, that characters -127,-115,-113,-112,-99 are not represented correctly.
I am unable to find out what might be the reason for this.
I am quit sure, that the problem is on the server side, as I tried the server application sending the characters from an externalhardware. The result was just the same.
This details is a real problem for me. My application uses binary data transmission. The fact that the 5 characters mentioned above are not recognized correctly, lead to data transmission errors.
Has anybody an idea ?
PS. Leaving out the ".getBytes" -statement (which I don#t know what it is - by the way) in the server code , the thing gets worse.
Maybe you or anybody else has time to try my little server client application. The client sends a complete range of charcters to the server. As you will notice, the strange thing is, that characters -127,-115,-113,-112,-99 are not represented correctly.
I am unable to find out what might be the reason for this.
I am quit sure, that the problem is on the server side, as I tried the server application sending the characters from an externalhardware. The result was just the same.
This details is a real problem for me. My application uses binary data transmission. The fact that the 5 characters mentioned above are not recognized correctly, lead to data transmission errors.
Has anybody an idea ?
PS. Leaving out the ".getBytes" -statement (which I don#t know what it is - by the way) in the server code , the thing gets worse.
Hi,
I've change your DataArrival handler as follows:
The resulting behaviour looks not perfect but more convincing than before.
There seems to be a problem with automatic casting bytes into integers.
The "and 255" prevents converting a byte into a negative integer.
"getbytes" reads the incoming bytes from the socket into an array of bytes.
Happy experimenting!
A1880
I've change your DataArrival handler as follows:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long) Dim Data() As Byte Dim l As Long Dim i As Integer Data = tcpServer.GetData.getBytes Text3.Text = Text3.Text & vbCrLf & bytesTotal & " bytes: [" & LBound(Data) & " .. " & UBound(Data) & "]" & vbCrLf For l = 0 To bytesTotal i = data(l) And 255 Text3.Text= Text3.Text & l & ": " & Chr$(i) & " " & CStr(i) & vbCrLf Next l End Sub |
The resulting behaviour looks not perfect but more convincing than before.
There seems to be a problem with automatic casting bytes into integers.
The "and 255" prevents converting a byte into a negative integer.
"getbytes" reads the incoming bytes from the socket into an array of bytes.
Happy experimenting!
A1880
Hi Vicente,
sorry! I haven't noticed that.
I guess that this has something to do with String encoding in Java.
The Jabaco framework takes Winsock data as Strings, not as arrays of bytes.
If your are using the following DataArrival handler, you see what bytes arrive:
The "63" is just a question mark "?" indicating that a given byte value is no valid character for String encoding "ISO-8859-1".
ISO-8859-1 is the character encoding used internally for the Chr() function.
Greetings
A1880
sorry! I haven't noticed that.
I guess that this has something to do with String encoding in Java.
The Jabaco framework takes Winsock data as Strings, not as arrays of bytes.
If your are using the following DataArrival handler, you see what bytes arrive:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long) Dim l As Long Dim i As Integer Dim s As java#lang#String = tcpServer.GetData() Text3.Text = Text3.Text & vbCrLf & bytesTotal & " bytes: " & vbCrLf For l = 0 To bytesTotal - 1 i = s.charAt(l) Text3.Text= Text3.Text & l & ": " & Chr$(i) & " " & CStr(i) & vbCrLf Next l End Sub |
The "63" is just a question mark "?" indicating that a given byte value is no valid character for String encoding "ISO-8859-1".
ISO-8859-1 is the character encoding used internally for the Chr() function.
Greetings
A1880
Similar threads
-
Tips, Tricks, Samples & Tutorials »-
db2000 lightchat
(Feb 10th 2009, 5:47pm)
-
Allgemeine Themen, Fragen und Diskussionen »-
UDP on winsocket
(May 28th 2009, 6:33pm)
-
General topics, questions and discussions »-
Jabaco and MultiSocket Server
(Mar 17th 2009, 10:00pm)
