Help with debugging astreams code

khos

Member
Licensed User
Longtime User
Hi everyone,

Could I ask for your help, if you could take a look at this screenshot:

attachment.php


Why is the Astreams.write method giving a nullpointerexception? it works once but not a 2nd time in the same code?

Any advise would be most appreciated of course.
Kim
 

Attachments

  • debug-screenshot.jpg
    debug-screenshot.jpg
    91.7 KB · Views: 492

flyingbag

Member
Licensed User
Longtime User
Your Astreams Object is not initialized
Thats why you see "AStreams Status Pre-send: false"

Since you have commented out the line in the sub this is not being trapped:
'If AStreams.IsInitialized = False Then Return

Most Likely:
In User Pause - you are closing the socket and Asyncstreams
When you resume - are you re-connecting the socket in Activity Resume?
Maybe you can add this code in
sub Activity_Resume
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.1.21", 12345, 10000)
end sub
 
Last edited:
Upvote 0

khos

Member
Licensed User
Longtime User
Hi flyingbag, many thanks for your help, I tried your code but it makes no difference, the reason why I commented out the line was to show the Astreams.write method giving a nullpointerexception, that does not seem normal to me.

"In User Pause - you are closing the socket and Asyncstreams" If Ileave the main window/activity in view and press the button again to call the astreams code again in the button1 code/method, that is not pausing, or is it?

Do any/all object/elements/controls etc have to reinitialized everytime you want to use them? I am not sure of that... unless there is a cleanup process somewhere getting rid of it automatically maybe?

I guess the question is, how can I keep the AStreams alive/initialized? Why does this object go away when used once?

Maybe Erel (Oh ye master of B4A) could give his imput?

Kim
 
Upvote 0

khos

Member
Licensed User
Longtime User
Yes Erel you could be right here, thanks, I was using Asynchronous Server Socket Example and I think that closes the connection after one go! Hmmm, I know it is not the place to ask but should anyone know how to change the code on the article to have the socket stay open that would be great.

If not, no worries.
Kim
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Maybe the other side is closing the connection? When the connection gets closed, AsyncStreams releases the held sockets. In the next update of AsyncStreams, the write operation will just be ignored instead of throwing a NullPointerException.

Are you handling the Error and Terminated events?

But erel, if we don't receive an error how shall we catch the released socket? I presume by using simply the terminated sub?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Yes Erel you could be right here, thanks, I was using Asynchronous Server Socket Example and I think that closes the connection after one go! Hmmm, I know it is not the place to ask but should anyone know how to change the code on the article to have the socket stay open that would be great.

If not, no worries.
Kim

You can create a 'close socket' command. upon receival, you close the socket. I've done this with vb6, worked great.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Good morning Erel (or afternoon),
I have a TCPService running as a service.
In my MAIN, I start several other activities. I noted above in this post, that a suggestion to re-initialize the Socket upon Activity_Resume was suggested.
I am having issues with the TCP socket getting closed, but when I just let the service run without my MAIN activity running other activities, my socket stays connected forever.
Can you suggest how I might need to restore or maintain the socket connection when my app is doing all these activities?
I thought that putting the TCP code in a service would avoid such issues.
Regards,
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Sorry, Erel, I associated the Astreams thread with what I was doing with the TCP communications. I apologize.

Rusty
 
Upvote 0
Top