#!/usr/bin/python
import os import sys import socket import sqlite3 as lite
global s s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
class client:
#functions on the client side only send the data to the server side (their only job)
def login(ID, password):
try:
s.send(self, ID)
s.send(password)
except IOError:
print "Error! Cannot execute statement."
def signup(self, ID, Name, Email, Password):
try:
s.send(ID, Name)
s.send(Email, Password)
except IOError:
print "Error! Cannot execute statement."
def addContact(self, ID, name, email):
try:
s.send(ID, name)
s.send(email)
except IOError:
print "Error! Cannot execute statement."
class main: # create a socket object c = client() Register = "Register" Login = "Login"
# get local machine name
host = socket.gethostname()
port = 9999
# connection to hostname on the port.
s.connect((host, port))
Message = input("Login if you are a user. If you are new, register here so you could play checkers! \t")
if Message == Login:
ID = input("ID \t")
password = input("Password \t")
c.login(ID, password)
elif Message == Register:
ID = input("ID \t")
Name = input("Name \t")
Email = input("Email \t")
Password = input("Password \t")
c.signup(ID, Name, Email, Password)
elif Message == add:
ID = input("ID \t")
Name = input("Name \t")
Email = input("Email \t")
c.addContact(ID, name, email)
else:
exit()
# Receive no more than 1024 bytes
data = s.recv(1024)
s.close()
print("The time got from the server is %s" % data.decode('ascii'))
Aucun commentaire:
Enregistrer un commentaire