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 (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 (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:
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
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?
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
Quote from: Biterider 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 (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 (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:
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!
Hi LiaoMi
QuoteYou 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
Quote from: LiaoMi on March 21, 2020, 07:45:46 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.
Quote from: Biterider on March 21, 2020, 10:18:17 PM
QuoteYou 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