0

Someone know how can I send string by socket qpython3 android (client) to python2.7 linux (server)?

For python2.7 linux (server) ok, I know, but I dont know how create the client with qpython3 android.

Someone Know?

TKS

2 Answers2

0

My code for server in linux:

import socket
HOST = ''
PORT = 5000
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
orig = (HOST, PORT)
tcp.bind(orig)
tcp.listen(1)
while True:
    con, client = tcp.accept()
    print 'Connected by', client
    while True:
        msg = con.recv(1024)
        if not msg: break
        print cliente, msg
    print 'Ending client connection', client
    con.close()

For client in android:

import sl4a
import socket
HOST = '127.0.0.1'
PORT = 5000
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dest = (HOST, PORT)
tcp.connect(dest)
print 'Press x to close'
msg = droid.dialogGetInput('Text', 'Input value').result
while msg <> 'x':
    tcp.send ((msg).encode('utf-8'))
    msg = droid.dialogGetInput('Text', 'Input value').result
tcp.close()

But this send erro on android:

socket.error: [Errno 111] Connection refused

Do U know wats happening? Tks

0

It's your loopback address this wont work HOST = '127.0.0.1' Instead that use true ip address on network for your host and make sure port of 5000 on server is open already

  • In your android client side instead of ```HOST = '127.0.0.1'``` put a valid address iand in your server if your sever is unix based system with ```ifconfig``` command and if it's Windows ```ipconfig``` look for your connection to Ethernet ip and put that into it most of time it's eth0 – milad hashemzadeh Sep 21 '21 at 21:45