Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pickle
- import SpaceTravelers
- import socket
- """
- A simple client that sends a Journey object to the server
- same provisos apply as NetworkUnpickler
- """
- def main():
- spaceship = SpaceTravelers.Spaceship("Galaxy", 10)
- planet = SpaceTravelers.Planet("Neptune", 13)
- #a tuple containing a spaceship and a planet
- journey = SpaceTravelers.Journey(spaceship, planet)
- print(journey.spaceship.info())
- print(journey.planet.info())
- print("We're about to be pickled !!!")
- HOST, PORT = "127.0.0.1", 6668
- # Create a socket (SOCK_STREAM means a TCP socket)
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- # Connect to server and send data
- sock.connect((HOST, PORT))
- print("Connected to " + HOST + ":" + str(PORT))
- stargate = sock.makefile('wb')
- pickle.dump(journey, stargate, pickle.HIGHEST_PROTOCOL )
- finally:
- sock.close()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement