lessons period 2
This commit is contained in:
65
period_2/02-sockets/902/Client_test.py
Normal file
65
period_2/02-sockets/902/Client_test.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from TxBlock import *
|
||||
from Transaction import *
|
||||
from Signature import *
|
||||
|
||||
from SocketUtil import *
|
||||
|
||||
SERVER = 'localhost'
|
||||
TCP_PORT = 5050
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
alex_prv, alex_pbc = generate_keys()
|
||||
mike_prv, mike_pbc = generate_keys()
|
||||
rose_prv, rose_pbc = generate_keys()
|
||||
mara_prv, mara_pbc = generate_keys()
|
||||
|
||||
Tx1 = Tx()
|
||||
Tx1.add_input(alex_pbc, 2.3)
|
||||
Tx1.add_output(mike_pbc, 1.0)
|
||||
Tx1.add_output(rose_pbc, 1.1)
|
||||
Tx1.sign(alex_prv)
|
||||
|
||||
Tx2 = Tx()
|
||||
Tx2.add_input(rose_pbc, 2.3)
|
||||
Tx2.add_input(mike_pbc, 1.0)
|
||||
Tx2.add_output(alex_pbc, 3.1)
|
||||
Tx2.sign(mike_prv)
|
||||
Tx2.sign(rose_prv)
|
||||
|
||||
B1 = TxBlock(None)
|
||||
B1.addTx(Tx1)
|
||||
B1.addTx(Tx2)
|
||||
|
||||
server = newServerSocket(SERVER)
|
||||
|
||||
print('A connection to the server is established.')
|
||||
|
||||
# -------------------------------------
|
||||
sendObj(SERVER, Tx2)
|
||||
print('Server is in Receiving mode ...')
|
||||
Obj = recvObj(server)
|
||||
if Obj:
|
||||
print('Data: ', type(Obj),'\n')
|
||||
else:
|
||||
print('No object received')
|
||||
|
||||
# -------------------------------------
|
||||
sendObj(SERVER, B1)
|
||||
print('Server is in Receiving mode ...')
|
||||
Obj = recvObj(server)
|
||||
if Obj:
|
||||
print('Data: ', type(Obj),'\n')
|
||||
else:
|
||||
print('No object received')
|
||||
|
||||
# -------------------------------------
|
||||
print('Server is in Receiving mode ...')
|
||||
Obj = recvObj(server)
|
||||
if Obj:
|
||||
print(Obj)
|
||||
else:
|
||||
print('No object received')
|
||||
|
||||
print("Success! The connection is released.") # If returns after time, then successful
|
||||
server.close()
|
Reference in New Issue
Block a user