You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

vicente

Beginner

  • "vicente" started this thread

Posts: 4

Date of registration: Feb 25th 2010

  • Send private message

1

Thursday, February 25th 2010, 9:41pm

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

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Friday, February 26th 2010, 9:51am

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

vicente

Beginner

  • "vicente" started this thread

Posts: 4

Date of registration: Feb 25th 2010

  • Send private message

3

Thursday, March 11th 2010, 12:06am

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.
vicente has attached the following file:
  • server_client.zip (5.31 kB - 353 times downloaded - latest: Aug 10th 2020, 10:32pm)

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

4

Thursday, March 11th 2010, 10:15am

Hi,
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

vicente

Beginner

  • "vicente" started this thread

Posts: 4

Date of registration: Feb 25th 2010

  • Send private message

5

Thursday, March 11th 2010, 10:42pm

Hello A1880,

did you notice, that characters 129,141,143,144 and 157 are represented as 63 ? That is my problem.

Greetings
Vicente

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

6

Friday, March 12th 2010, 12:06am

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:

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

Rate this thread
WoltLab Burning Board