API login problem - !fatal not logged in

Hi,

I’m using VB6 and Chillcat Socket component. when I send first /login i got this response

!fatal
not logged in

Private Sub Form_Load()
Dim socket As New ChilkatSocket

Dim success As Long
success = socket.UnlockComponent(“Anything for 30-day trial”)
If (success <> 1) Then
MsgBox “Failed to unlock component”
Exit Sub
End If

’ Connect to the program at some host:port that is expecting
’ to receive the file. In this case, the receiver is at
’ localhost:5555
Dim ssl As Long
ssl = 0
Dim maxWaitMillisec As Long
maxWaitMillisec = 1000
'socket.StringCharset = “ascii”
success = socket.Connect(“192.168.254.1”, 8728, ssl, maxWaitMillisec)
If (success <> 1) Then
MsgBox socket.LastErrorText
Exit Sub
End If

'Set maximum timeouts for reading an writing (in millisec)
socket.MaxReadIdleMs = 1000
socket.MaxSendIdleMs = 1000

’ Send the byte count:
success = socket.SendCount(LenB(“/login”))
If (success <> 1) Then
MsgBox socket.LastErrorText
Exit Sub
End If

’ Send the file data.
success = socket.SendBytes(“/login”)
If (success <> 1) Then
MsgBox socket.LastErrorText
Exit Sub
End If
DoEvents

’ Send zero character
success = socket.SendString(0)
If (success <> 1) Then
MsgBox socket.LastErrorText
Exit Sub
End If

DoEvents

Debug.Print "Response : " & socket.ReceiveString
DoEvents

’ Close the connection with the server
’ Wait a max of 20 seconds (20000 millsec)
socket.Close 2000
End Sub

I tried to add length as (LenB(“/login”) +1) no difference

Any suggestions ?

Thank you

Vaclav Prokes

I always send the zero with “/login”. It should be something like this:

success = socket.SendBytes("/login" & Chr(0))

Thanks for starting the new thread! :smiley:

Hi,

still no difference =:o( I have send the request to Chillcat sw how to send Zero character

Thenk you

V.

Don’t know if you found this wiki, but it might help if you don’t want to use Chillkat.
http://wiki.mikrotik.com/wiki/API_in_VB_dot_NET

Hi,

yes I found it, but the example is for VB.NET, but I have to use VB6.
I could not find the same objects for VB6 as used in VB.NET example =:o(

Thank you

V.

While checking something else, I found a potential problem.

success = socket.SendCount(LenB(“/login”))

SendCount sends a 4 byte (integer) value. You only want to send one byte in this case. Should be Chr(7).
You might want to check if the ChillKat SendString() routine sends the terminating zero.

ADD:I think I would try this:

success = socket.SendString(Chr(7) & "/login")

No other send. No SendCount or SendBytes. I have a feeling that the difference between SendBytes and SendString would be the terminating zero character. What do you think? Worth a try?

EDIT: I think maybe the value should be Chr(6). Now that I think about it more, the last character is sent by itself (zero) denoting “no characters remaining”, or “end”. I don’t have my Java code here to check.

The edit is correct – it should be sending “/login” then “” denoting the end of the sentence, so chr(6) & “/login” & chr(0) & null_str