Skip to content

Instantly share code, notes, and snippets.

@MinaGabriel
Created November 17, 2016 00:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MinaGabriel/c97b7a22c40c94b283723c7226dc9b68 to your computer and use it in GitHub Desktop.
Save MinaGabriel/c97b7a22c40c94b283723c7226dc9b68 to your computer and use it in GitHub Desktop.
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!'
@invlpga
Copy link

invlpga commented Jul 15, 2018

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