Python socket program Server/ Client with Android Client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
****************** 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!' |
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
Dude I have to turn the Clint into a apk?