Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python socket program Server/ Client with Android Client
****************** Server ********************
import socket
import sys
HOST = '192.168.142.160' #this is your localhost
PORT = 8888
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#socket.socket: must use to create a socket.
#socket.AF_INET: Address Format, Internet = IP Addresses.
#socket.SOCK_STREAM: two-way, connection-based byte streams.
print 'socket created'
#Bind socket to Host and Port
try:
s.bind((HOST, PORT))
except socket.error as err:
print 'Bind Failed, Error Code: ' + str(err[0]) + ', Message: ' + err[1]
sys.exit()
print 'Socket Bind Success!'
#listen(): This method sets up and start TCP listener.
s.listen(10)
print 'Socket is now listening'
while 1:
conn, addr = s.accept()
print 'Connect with ' + addr[0] + ':' + str(addr[1])
buf = conn.recv(64)
print buf
s.close()
**************Client**************************
import socket
import sys
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.142.160', 8888)) #IP is the server IP
for args in sys.argv:
if args == "":
args = 'no args'
else:
s.send(args + ' ')
print 'goodbye!'
@PopcornFilling
Copy link

Dude I have to turn the Clint into a apk?

@markusbeyer
Copy link

Yes how do we turn it into an apk simply...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment