Advertisement
Guest User

serwer

a guest
Mar 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. // WZR_serwer.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include <windows.h>
  5. #include <time.h>
  6. #include <stdio.h>
  7. #include <vector>
  8. #include "siec.h"
  9. #include "kwaternion.h"
  10.  
  11. struct StanObiektu
  12. {
  13. int iID; // identyfikator obiektu
  14. Wektor3 wPol; // polozenie obiektu (środka geometrycznego obiektu)
  15. kwaternion qOrient; // orientacja (polozenie katowe)
  16. Wektor3 wV, wA; // predkosc, przyspiesznie liniowe
  17. Wektor3 wV_kat, wA_kat; // predkosc i przyspieszenie liniowe
  18. float masa;
  19. };
  20.  
  21. enum typy_ramek { STAN_OBIEKTU, INFO_O_ZAMKNIECIU, OFERTA };
  22.  
  23.  
  24. struct Ramka // główna struktura służąca do przesyłania informacji
  25. {
  26. int typ;
  27. StanObiektu stan;
  28. float wartosc_oferty;
  29. };
  30.  
  31. unicast_net *uni_receive;
  32. unicast_net *uni_send;
  33.  
  34. std::vector<unsigned long> klienci;
  35. Ramka ramka;
  36. StanObiektu stan;
  37.  
  38. int main()
  39. {
  40. uni_receive = new unicast_net(10001);
  41. uni_send = new unicast_net(10002);
  42.  
  43. while (1) {
  44. int rozmiar;
  45. unsigned long adres;
  46. rozmiar = uni_receive->reciv((char*)&ramka, &adres, sizeof(Ramka));
  47.  
  48. switch (ramka.typ) {
  49. case typy_ramek::STAN_OBIEKTU:
  50. printf("stan");
  51. }
  52.  
  53. bool found = false;
  54. int position = -1; //dopisane
  55. for (int i = 0; i < klienci.size(); i++) {
  56. if (klienci[i] == adres) {
  57. found = true;
  58. position = i; //dopisane
  59. break;
  60. }
  61. }
  62.  
  63. if (!found) {
  64. klienci.push_back(adres);
  65. printf("Connected %lu", adres);
  66. }
  67.  
  68. for (int i = 0; i < klienci.size(); i++) {
  69. printf("To %lu (%d)\n", klienci[i], klienci.size());
  70. uni_send->send((char*)&ramka, klienci[i], sizeof(Ramka));
  71. }
  72.  
  73. /*dopisane*/
  74. if (ramka.typ == typy_ramek::INFO_O_ZAMKNIECIU) {
  75. printf("Zamkniecie polaczenia %lu", adres);
  76. klienci.erase(klienci.begin() + position);
  77. }
  78.  
  79. }
  80.  
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement