Author Topic: Mobile App  (Read 558 times)

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 533
  • ObjAsm Developer
    • ObjAsm
Mobile App
« on: March 15, 2020, 02:28:46 AM »
Hi
This was an exciting week!

For the first time I was able to connect my mobile device with the PC using the NetCom framework (http://masm32.com/board/index.php?topic=7757.0)
As I mentioned in the database post (http://masm32.com/board/index.php?topic=8352.0), I have coded an app using Kotlin, a kind of relative new, improved java dialect. The code is very easy to understand and the learning curve of this language is very easy. There are countless examples on the net that you only have to put together after learning the basics of the language.

There are a few small steps to take to enable communication. In the local network, the port forwarding and the firewall setup must be adjusted so that the messages can be forwarded to our server.

The server code is basically the code from "ObjAsm\examples\X\NetCom\Server" with a slight change of the ServerProtocol.inc. When a button on the phone is pressed, the client sends a zero terminated UTF8 message and the server responds with a "modified UTF8" string. In this implementation, a simple "OK" is returned and displayed at the bottom of the phone screen.

Now that the client/server communication and the database are working, a suitable protocol must be established for the entire project.

There are so many uses of this framework to explore, that I don’t know where to start…

This is the code of the Kotlin client class:

Code: [Select]
class NetComClient(private val serverAddress: String, private val serverPort:Int) {
    lateinit var clientsocket: Socket
    lateinit var dataInputStream:DataInputStream
    var connected = FALSE
    var information = ""

    init {
        try {
            clientsocket = Socket(serverAddress, serverPort)
            dataInputStream = DataInputStream(clientsocket.getInputStream())
            connected = TRUE
        } catch (ex: Exception) {
            information = when (ex) {
                is ProtocolException -> "Bad Protocol"
                is PortUnreachableException -> "Port unreachable"
                is NoRouteToHostException -> "No route to host"
                is ConnectException -> "Connection failed"
                is UnknownHostException -> "Unknown Host"
                is BindException -> "Socket binding failed"
                is IOException -> "IO failed"
                is SocketException -> "Socket failed"
                else -> throw ex
            }
        }
    }

    fun send(message: String) {
        if (connected != FALSE) {
            try {
                clientsocket.outputStream.write("$message\u0000".toByteArray())
            } catch (ex: Exception) {
                information = when (ex) {
                    is ProtocolException -> "Bad Protocol"
                    is PortUnreachableException -> "Port unreachable"
                    is NoRouteToHostException -> "No route to host"
                    is ConnectException -> "Connection failed"
                    is UnknownHostException -> "Unknown Host"
                    is BindException -> "Socket binding failed"
                    is IOException -> "IO failed"
                    is SocketException -> "Socket failed"
                    else -> throw ex
                }
            }
        }
    }

    fun read(): String {
        try {
            var response: String
            response = dataInputStream.readUTF()
            return response
        } catch (ex: Exception) {
            information = when (ex) {
                is ProtocolException -> "Bad Protocol"
                is PortUnreachableException -> "Port unreachable"
                is NoRouteToHostException -> "No route to host"
                is ConnectException -> "Connection failed"
                is UnknownHostException -> "Unknown Host"
                is BindException -> "Socket binding failed"
                is IOException -> "IO failed"
                is SocketException -> "Socket failed"
                is EOFException -> "EOF reached"
                else -> throw ex
            }
            return information
        }
    }

    fun disconnect() {
        if (connected != FALSE) {
            try {
                clientsocket.close()
                connected = FALSE
            } catch (ex: Exception) {
                information = when (ex) {
                    is ProtocolException -> "Bad Protocol"
                    is PortUnreachableException -> "Port unreachable"
                    is NoRouteToHostException -> "No route to host"
                    is ConnectException -> "Connection failed"
                    is UnknownHostException -> "Unknown Host"
                    is BindException -> "Socket binding failed"
                    is IOException -> "IO failed"
                    is SocketException -> "Socket failed"
                    else -> throw ex
                }
            }
        }
    }
}

Biterider

daydreamer

  • Member
  • *****
  • Posts: 1321
  • building nextdoor
Re: Mobile App
« Reply #1 on: March 15, 2020, 09:03:11 PM »
great :thumbsup:
so you can also sit away from home and send/recieve from home after developed further?only need to know IP of phone?

Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 533
  • ObjAsm Developer
    • ObjAsm
Re: Mobile App
« Reply #2 on: March 16, 2020, 12:03:13 AM »
Hi
One of the first things I did was load the app from the emulator onto a real phone. I went to the bus stop and tried to communicate with the server from there. It worked wonderfully.  :eusa_dance:
Now there are no limits to the imagination to make something useful of it.

Biterider

LiaoMi

  • Member
  • ****
  • Posts: 697
Re: Mobile App
« Reply #3 on: March 21, 2020, 07:45:46 PM »
Hi
This was an exciting week!

For the first time I was able to connect my mobile device with the PC using the NetCom framework (http://masm32.com/board/index.php?topic=7757.0)
As I mentioned in the database post (http://masm32.com/board/index.php?topic=8352.0), I have coded an app using Kotlin, a kind of relative new, improved java dialect. The code is very easy to understand and the learning curve of this language is very easy. There are countless examples on the net that you only have to put together after learning the basics of the language.

There are a few small steps to take to enable communication. In the local network, the port forwarding and the firewall setup must be adjusted so that the messages can be forwarded to our server.

The server code is basically the code from "ObjAsm\examples\X\NetCom\Server" with a slight change of the ServerProtocol.inc. When a button on the phone is pressed, the client sends a zero terminated UTF8 message and the server responds with a "modified UTF8" string. In this implementation, a simple "OK" is returned and displayed at the bottom of the phone screen.

Now that the client/server communication and the database are working, a suitable protocol must be established for the entire project.

There are so many uses of this framework to explore, that I don’t know where to start…

This is the code of the Kotlin client class:

Code: [Select]
class NetComClient(private val serverAddress: String, private val serverPort:Int) {
    lateinit var clientsocket: Socket
    lateinit var dataInputStream:DataInputStream
    var connected = FALSE
    var information = ""

    init {
        try {
            clientsocket = Socket(serverAddress, serverPort)
            dataInputStream = DataInputStream(clientsocket.getInputStream())
            connected = TRUE
        } catch (ex: Exception) {
            information = when (ex) {
                is ProtocolException -> "Bad Protocol"
                is PortUnreachableException -> "Port unreachable"
                is NoRouteToHostException -> "No route to host"
                is ConnectException -> "Connection failed"
                is UnknownHostException -> "Unknown Host"
                is BindException -> "Socket binding failed"
                is IOException -> "IO failed"
                is SocketException -> "Socket failed"
                else -> throw ex
            }
        }
    }

    fun send(message: String) {
        if (connected != FALSE) {
            try {
                clientsocket.outputStream.write("$message\u0000".toByteArray())
            } catch (ex: Exception) {
                information = when (ex) {
                    is ProtocolException -> "Bad Protocol"
                    is PortUnreachableException -> "Port unreachable"
                    is NoRouteToHostException -> "No route to host"
                    is ConnectException -> "Connection failed"
                    is UnknownHostException -> "Unknown Host"
                    is BindException -> "Socket binding failed"
                    is IOException -> "IO failed"
                    is SocketException -> "Socket failed"
                    else -> throw ex
                }
            }
        }
    }

    fun read(): String {
        try {
            var response: String
            response = dataInputStream.readUTF()
            return response
        } catch (ex: Exception) {
            information = when (ex) {
                is ProtocolException -> "Bad Protocol"
                is PortUnreachableException -> "Port unreachable"
                is NoRouteToHostException -> "No route to host"
                is ConnectException -> "Connection failed"
                is UnknownHostException -> "Unknown Host"
                is BindException -> "Socket binding failed"
                is IOException -> "IO failed"
                is SocketException -> "Socket failed"
                is EOFException -> "EOF reached"
                else -> throw ex
            }
            return information
        }
    }

    fun disconnect() {
        if (connected != FALSE) {
            try {
                clientsocket.close()
                connected = FALSE
            } catch (ex: Exception) {
                information = when (ex) {
                    is ProtocolException -> "Bad Protocol"
                    is PortUnreachableException -> "Port unreachable"
                    is NoRouteToHostException -> "No route to host"
                    is ConnectException -> "Connection failed"
                    is UnknownHostException -> "Unknown Host"
                    is BindException -> "Socket binding failed"
                    is IOException -> "IO failed"
                    is SocketException -> "Socket failed"
                    else -> throw ex
                }
            }
        }
    }
}

Biterider

Hi Biterider,

cool project, I personally never programmed mobile devices, this project shows all the capabilities of assembler in a new light. You got me interested in the Kotlin language  :thumbsup:, thanks for the example!

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 533
  • ObjAsm Developer
    • ObjAsm
Re: Mobile App
« Reply #4 on: March 21, 2020, 10:18:17 PM »
Hi LiaoMi
Quote
You got me interested in the Kotlin language  :thumbsup:
I'm still learning Kotlin, which claims to be the better Java in many ways, but it also has a lot in common.
Both are the exact opposite of what we normally do in assembler and you need a complete different mindset to approach it.
Nevertheless, this project proves to me that it is possible to work together with languages as diverse as assembler and a very high language like Kotlin (reminds me of real life  :biggrin:).

I wish you the best of luck with your endeavor.

Biterider

anta40

  • Member
  • ***
  • Posts: 312
Re: Mobile App
« Reply #5 on: March 21, 2020, 10:49:58 PM »
You got me interested in the Kotlin language  :thumbsup:, thanks for the example!

Please give it a try  :thumbsup:
One of criticism points against Java is "too verbose". Kotlin allows you to write shorter code.

daydreamer

  • Member
  • *****
  • Posts: 1321
  • building nextdoor
Re: Mobile App
« Reply #6 on: March 22, 2020, 07:26:28 PM »
Quote
You got me interested in the Kotlin language  :thumbsup:
I'm still learning Kotlin, which claims to be the better Java in many ways, but it also has a lot in common.
Both are the exact opposite of what we normally do in assembler and you need a complete different mindset to approach it.
Nevertheless, this project proves to me that it is possible to work together with languages as diverse as assembler and a very high language like Kotlin (reminds me of real life  :biggrin:).
Haven't got far with my  phone apps,but every OS has similar api's which is helpful winapi richedit has settext, gettext, so does phone textarea too
So i think it would be possible make a simple text game, but instead print to console,string handling followed by settext
So you see even asm with winapi and android os has some similarities
So maybe we who are interested in mobile apps could work together  sharing our experience about it
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)