I have the following code. This is a working code I used to send one digit number to the server (VB6) except that times the is a delay and the server received a message with more digits instead of 1 (i send a digit when i press a particular button, so pressing in a row eg 3 buttons, I expect the server to receive 3 messages with 1 digit length. But there are times I am receiving a message with 3 digits! is there any references regarding known bugs of Vb6 + MsWinsck.ocx ?
Thanking the colleges in advance
Thanking the colleges in advance
B4X:
Sub btnConnect_Click
Select Case btnConnect.Text
Case "Connect"
btnConnect.Text = "Disconnect"
Socket1.Initialize("Socket1")
Socket1.Connect("xxx.xxx.x.xxx",9000,15000)
Case "Disconnect"
btnConnect.Text = "Connect"
Socket1.Close
Case Else
End Select
End Sub
Sub Socket1_Connected(Connected As Boolean)As Boolean
If Connected = True Then
ToastMessageShow("Connected",True)
AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams")
SendData("+") 'send + as a sign of succesfull link
Else
ToastMessageShow("Server not available",True)
btnConnect.Text = "Connect"
End If
btnConnect.Enabled = True
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "Windows-1252")
log(msg)
End Sub
Sub SendData(msg As String)
Dim Buffer() As Byte
Buffer = Msg.GetBytes("Windows-1252")
AStreams.Write(Buffer)
End Sub
Sub Buttons_Click
Dim btn As Button
Dim msg As String
Dim b As Beeper
btn = Sender
b.Beep
msg = btn.Tag
SendData(msg)
End Sub
- Also while the code above is working, sometimes when the program runs for the very first time I got a crash. The reference line where the eroor happens is the "AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams")"
LogCat connected to: 07961702
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
1920 x 1104, scale = 2.0 (320 dpi)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (socket1_connected)
running waiting messages (1)
Error occurred on line: 123 (main)
main$ResumeMessagerun (java line: 252)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.SocketWrapper.getInputStream(SocketWrapper.java:133)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:485)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:174)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA$3.run(BA.java:312)
at anywheresoftware.b4a.BA.setActivityPaused(BA.java:382)
Last edited by a moderator: