Code from this example does not close the connection, it just dies when the connection is lost;)
def readStr(self, length):
ret = ''
while len(ret) < length:
s = self.sk.recv(length - len(ret))
if s == '': raise RuntimeError, "connection closed by remote end"
ret += s
return ret
But it’s not the point.
I can’t logout “grecefully” regardles of logout style.
Logout initiated from mt is useless just the same as initiated from client.
But it’s not the point.
I can’t logout “grecefully” regardles of logout style.
Logout initiated from mt is useless just the same as initiated from client.
I think it is the point. I don’t send “/quit” to my router from the client. I close the connection. Just like the s.connect() in the python code, I have a Java version of s.close(). Immediate logout.
I can make persistent API sessions (start a daemon which can hold opened sessions, but it is evil ;> ), but hey - API is about 4 years old it should be mature at this time and it should work as expected for fsck sake!
Well, everything is fine with it, except for that session timeout problem.. But hey, in their new branch of RouterOS it’s fixed!. So you can’t really blame Mikrotik for not doing anything. You will have to move to v5 eventually, anyway.
I am too struggling with this problem, since I’ve not yet moved to v5.. And I think it would be best if they would have included a fix for it in their new versions of v4.. Reasons why they didn’t are not known: is it something difficult to achieve in v4, or is it their marketing strategy for attracting users to use v5, even if they’re perfectly happy with for example v4.
Idea of using a daemon which maintains a single always opened session and accepts queries is actually very interesting, only if someone would have thought about it earlier and made a publicly available daemon This wouldn’t eliminate a problem for accessing ROS from mobile devices using API, but at least *nix machines could use API without any limitations. Too bad many people will go to v5 from v4 soon, just as they did a migration from v3 to v4 some time ago..
After checking my V4.14 test router, the logouts (according to the user sessions) were not clean. I am not sure when the session logout problem started because the logins and logouts went smooth in all versions, even V4.14. But since I don’t login and logout with every command, it isn’t a big deal. I had six open sessions in a month, and three were tests for forum users with questions.
Glad to hear it is fixed in the new version. Mikrotik has been very good about fixing any bugs I have reported. I want to see V5.x debugged so I can use PayPal without the dns cache script I must use now.
BTW, I don’t have a problem with my mobile device. My Blackberry phone does a great job of keeping the connection open. One login, a bunch of changes, and one logout. The only inconvenient part was the payment to Research In Motion to use the MD5 encryption in the Blackberry. Maybe someday I will post the code if anyone is interested.
This is one of the things that bothers me. How come you get this number that high and I’m stuck at around 150 with that “challenge error”? What it depends from?
[admin@MikroTik] > user active print count-only
53407
[admin@MikroTik] >
If that is over a period of 122 days, that is an average of 437 logins every day.
I like the thread handling my connection! Six in a month is much better!
FYI: At that rate, it would take me 741 years to get that number.
yep, persistent connections rule, but do you have an experience with v5? for me, rc4 gives timeouts frequently (>100 times a day, with ~500 executions), so I need to reconnect anyway
@Chupaka: I have no experience with V5.x. I am waiting for a stable release. I’m using V4.16 on most routers. The API logout fix is just one of a couple things I am looking forward to. The PayPal walled garden fix is the one that will help me the most!
I noticed you haven’t been hanging around the forum as much as you used to. I miss reading your stuff!
there is a problem in RouterOS v4.x that API logins are not closed properly and stay listed in ‘/user active’ there is nothing you or me can do with API client to disconnect/close/leave the router to make them go away.
Code that fixed this problem in 5.0rc broke a lot of things and therefore cannot be safely back-ported to v4.x
on the bright side, active api logins that are hangin’ there does not consume resources, at least 100K hanging logins consumed approximately same amount of RAM as no hanging users.
In other words: We don’t give a f.. , complain to God.
Code that fixed this problem in 5.0rc broke a lot of things and therefore cannot be safely back-ported to v4.x
I dont’t want to be rude but… are You kidding me ?
So..split Your big "broke a lot of things " 4.x to 5.0rc patchinto smaller ones, and backport only the logout routine.
on the bright side, active api logins that are hangin’ there does not consume resources, at least 100K hanging logins consumed approximately same amount of RAM as no hanging users.
I also stumbled upon this problem today. The problem was that Mikrotik (RB1000) mysteriously stopped forwarding some new connections, as if something overflowed inside. TCP connections that were already established worked fine. Everything went back to normal just after reboot. Upon rebooting I saw in the log thousands of messages “user … logged out from … via api”. Router had about 23 days of uptime and the API connections were made 1-2 times a minute, sometimes more (quick calc gives more than 50.000 active API connections).
Around 3 weeks ago there also was mysterious behaviour fixed by rebooting RB1000. This lack of api logouts is the only symptom I observed.
Don’t know about VB, but maybe you should post the login part of your code. Insure you are sending the “end of command” zero character.
You send “/login” by itself (no user or password), then the router should return “!done”, followed by the chap challenge. I see it is returning “!fatal”, so you are at least communicating with the router, but you seem to have an error in the initial send part of the login.
You should start a new thread. Post the response to this in the new thread. Thanks!
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
It appears you are not sending the zero with “/login”. It must be in the same send as “/login”.
Normally in higher level languages, the strings are already zero terminated, so I just send one more character than the string length. Try setting the string length to 7 rather than 6. or use something like (LenB(“/login”) +1)