Advertisement
Guest User

Untitled

a guest
Aug 8th, 2012
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import pickle
  2. import SpaceTravelers
  3. import socket
  4.  
  5. """
  6. A simple client that sends a Journey object to the server
  7. same provisos apply as NetworkUnpickler
  8. """
  9.  
  10. def main():
  11. spaceship = SpaceTravelers.Spaceship("Galaxy", 10)
  12. planet = SpaceTravelers.Planet("Neptune", 13)
  13. #a tuple containing a spaceship and a planet
  14. journey = SpaceTravelers.Journey(spaceship, planet)
  15. print(journey.spaceship.info())
  16. print(journey.planet.info())
  17. print("We're about to be pickled !!!")
  18.  
  19. HOST, PORT = "127.0.0.1", 6668
  20. # Create a socket (SOCK_STREAM means a TCP socket)
  21. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  22. try:
  23. # Connect to server and send data
  24. sock.connect((HOST, PORT))
  25. print("Connected to " + HOST + ":" + str(PORT))
  26. stargate = sock.makefile('wb')
  27. pickle.dump(journey, stargate, pickle.HIGHEST_PROTOCOL )
  28.  
  29. finally:
  30. sock.close()
  31.  
  32. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement