PolyClient.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * PolyClient.h
  3. * Poly
  4. *
  5. * Created by Ivan Safrin on 3/6/09.
  6. * Copyright 2009 __MyCompanyName__. All rights reserved.
  7. *
  8. */
  9. // @package Network
  10. #pragma once
  11. #include "PolyLogger.h"
  12. #include "PolyGlobals.h"
  13. #include "PolyPeer.h"
  14. #include "PolyTimer.h"
  15. #include "PolyEvent.h"
  16. namespace Polycode {
  17. typedef struct {
  18. char dummy;
  19. } DummyData;
  20. class _PolyExport ClientEvent : public Event {
  21. public:
  22. ClientEvent(){}
  23. ~ClientEvent(){}
  24. char data[MAX_PACKET_SIZE];
  25. unsigned int dataSize;
  26. unsigned short dataType;
  27. static const int EVENT_SERVER_DATA = 0;
  28. static const int EVENT_CLIENT_READY = 1;
  29. };
  30. class _PolyExport Client : public Peer {
  31. public:
  32. Client(unsigned int port, int rate);
  33. ~Client();
  34. void updatePeer();
  35. void connect(string ipAddress, unsigned int port);
  36. void setPersistentData(void *data, unsigned int size);
  37. unsigned int getClientID();
  38. void sendReliableDataToServer(char *data, unsigned int size, unsigned short type);
  39. void handlePacket(Packet *packet, PeerConnection *connection);
  40. void handleEvent(Event *event);
  41. private:
  42. int clientID;
  43. void *data;
  44. unsigned int dataSize;
  45. Timer *rateTimer;
  46. Address serverAddress;
  47. bool connected;
  48. };
  49. }