Secure Sockets

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I am trying to create a app that will connect to a secure socket (SSL) and send a ASCII message to it but having a small issue in doing it with a username and password.

I am using this library: SocketSSL.zip

I am able to connect to my device with the secure SSL connection using this library.

However, the product I am connecting to allows you to set a username and password.

When I set a username and password in the product, then try and connect to it, it then requires a username and password to be able to connect to this secure socket.

If I try and connect to it without any username and password and I 'log' the reply from this connection it logs:

Username:

How can I include the username and password when I connect to this device?

Incase there is another way to do what I am trying to do, this is what I am trying to do:

Connect to a IPort (with a username and password) send a ASCII message to it and listen for a reply from this device.
Then, keep the connection open for any other reply's that it will automatically send without notice. (all ASCII based messages).
 

aaronk

Well-Known Member
Licensed User
Longtime User
Hi Erel,

I am using AsyncStreams to send the ASCII messages between the device and product.

I have attached code in a zip file for you to take a look at.

When I run this code on my device it logs the following:


If I remove the username and password in my product then connect to it, then it allows me to send data without any problems.

Based on my code in the example attached is there something I am missing to allow username and passwords as I am not sure how to do it?

You can connect to my device online if you want but I can't publish the IP or port in the forum but am happy to send it to your in a email or PM.
 

Attachments

  • ssl_socket_example.zip
    17.5 KB · Views: 210
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Did you copy these logs from the IDE? The ~i: tokens should have been removed.

I copied the log from the IDE but I was using the version before the version that just come out.


I still don't understand something. What is your server expecting?

I am not quite sure what you mean by this.

I will have to keep playing around to see how I can do the username and password in the SSL socket.


Edit: Using version 2.70 of B4A it doesn't show the ~i tokens.
 
Last edited:
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I have found out when I get a reply from my device I need to send a ASCII message to the device..

So for example, when I connect to the device it will automatically send a message 'Username:' then I need to send a ASCII message back to it for example 'aaron'.

However when I do send that message back I get a error in B4A.
Does anyone know what this following error means?

 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You are doing network operations on the main thread which is not allowed in later versions of Android because it slows the GUI responsiveness. Looking at the SocketSSL.jar the AsyncStreamsSSL.Write2 is directly writing to the output stream, for some reason that I cannot comprehend, and that is what is causing the error.
B4X:
aout.out.write("\n".getBytes());
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
So how do we fix this? Move it to a service?

EDIT: Nope, didn't work.

Oh, it's in the java code, not the B4A code. So only the guy who made the library can fix it.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
So how do we fix this? Move it to a service?

EDIT: Nope, didn't work.

Oh, it's in the java code, not the B4A code. So only the guy who made the library can fix it.

It's now working for me fine. (without modifying the Java Code, and I don't have the Java code only have the B4A Library)
I have used it in a Service Module in B4A and I have also tested it on Android 2.3 and Android 4.2.2 and works fine for both devices.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…