Search code examples
androidporttcpclientbeagleboneblackapp-inventor

In App Inventor Make TCP IP Client


Hi Guy's I'm new to programming Android device's I do have python, java, C#, C, C++, PHP, Bash and Visual Basic Experience but I'm new to this block programming, and I haven't done much work with forms. I'm trying to get make an application that posts data to an external IP. I have successsfully wrote a server and a windows based client, clicking buttons in my windows client posts data to the ip 192.168.1.9 port 9999. This is just in the testing phase to remote control a bunch of beaglebone gpio's. So far I've had great success with the windows side. In app inventor for android, However, I've created a series of buttons and tabs, different buttons post text or post and poll for response. The problem I have is that I can directly attach the web connector to 192.168.1.9 but when I add in the port 9999 it tells me the address is incorrect. The method I'm using is

when Screen1.initialize
do set Web1.Url to "http://192.168.1.9:9999"

when Button1.Click
do call Web1.PostText
             text > 0

Again, if I type in just the IP of the beaglebone I see its ethernet port go crazy when I click button1. It does nothing when I add in the port. Of course my server is running on 9999 since port 80 is reserved for the internet. Any suggestions?


Solution

  • I would like to suggest you a two-step solution.

    Step 1:

    Problem>>Develop an android app which is capable to communicate via TCP-IP.

    Solution>> I hope you are familiar with MIT-APP Inventor-2. Import an extension called ClientSocket extension V0.4.3 available here to app. Thanks to the developer of the extension.

    Step 2:

    Problem>>A server responding client request.

    Solution>> I have written a Python code.

    import socket               # Import socket module
    s = socket.socket()         # Create a socket object
    host = socket.gethostname() # Get local machine name
    port = 9000                 # Reserve a port for your service.
    s.bind((host, port))        # Bind to the port
    print (host)
    s.listen(5)
    while True:
       c, addr = s.accept()     # Establish connection with client.
       data=(str(c.recv(1024)))
       print data
       conn.commit()
       c.close()  
       cur.close()
    

    Hope this will help.