Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WZR_serwer.cpp : Defines the entry point for the console application.
- //
- #include <windows.h>
- #include <time.h>
- #include <stdio.h>
- #include <vector>
- #include "siec.h"
- #include "kwaternion.h"
- struct StanObiektu
- {
- int iID; // identyfikator obiektu
- Wektor3 wPol; // polozenie obiektu (środka geometrycznego obiektu)
- kwaternion qOrient; // orientacja (polozenie katowe)
- Wektor3 wV, wA; // predkosc, przyspiesznie liniowe
- Wektor3 wV_kat, wA_kat; // predkosc i przyspieszenie liniowe
- float masa;
- };
- enum typy_ramek { STAN_OBIEKTU, INFO_O_ZAMKNIECIU, OFERTA };
- struct Ramka // główna struktura służąca do przesyłania informacji
- {
- int typ;
- StanObiektu stan;
- float wartosc_oferty;
- };
- unicast_net *uni_receive;
- unicast_net *uni_send;
- std::vector<unsigned long> klienci;
- Ramka ramka;
- StanObiektu stan;
- int main()
- {
- uni_receive = new unicast_net(10001);
- uni_send = new unicast_net(10002);
- while (1) {
- int rozmiar;
- unsigned long adres;
- rozmiar = uni_receive->reciv((char*)&ramka, &adres, sizeof(Ramka));
- switch (ramka.typ) {
- case typy_ramek::STAN_OBIEKTU:
- printf("stan");
- }
- bool found = false;
- int position = -1; //dopisane
- for (int i = 0; i < klienci.size(); i++) {
- if (klienci[i] == adres) {
- found = true;
- position = i; //dopisane
- break;
- }
- }
- if (!found) {
- klienci.push_back(adres);
- printf("Connected %lu", adres);
- }
- for (int i = 0; i < klienci.size(); i++) {
- printf("To %lu (%d)\n", klienci[i], klienci.size());
- uni_send->send((char*)&ramka, klienci[i], sizeof(Ramka));
- }
- /*dopisane*/
- if (ramka.typ == typy_ramek::INFO_O_ZAMKNIECIU) {
- printf("Zamkniecie polaczenia %lu", adres);
- klienci.erase(klienci.begin() + position);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement