mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
have AgentList control the required UDPSocket instance
This commit is contained in:
parent
00211ddc3d
commit
9a514f56e5
5 changed files with 16 additions and 15 deletions
|
@ -57,7 +57,7 @@ const int MAX_PACKET_SIZE = 1500;
|
|||
char DOMAIN_HOSTNAME[] = "highfidelity.below92.com";
|
||||
char DOMAIN_IP[100] = ""; // IP Address will be used first if not empty string
|
||||
const int DOMAINSERVER_PORT = 40102;
|
||||
UDPSocket agentSocket(AGENT_SOCKET_LISTEN_PORT);
|
||||
|
||||
AgentList agentList;
|
||||
|
||||
// For testing, add milliseconds of delay for received UDP packets
|
||||
|
@ -226,7 +226,7 @@ void Timer(int extra)
|
|||
sprintf(output, "%c %f,%f,%f,%s %hd", 'I', location[0], location[1], location[2], localAddressBuffer, AGENT_SOCKET_LISTEN_PORT);
|
||||
std::cout << "sending " << output << " to domain server\n";
|
||||
int packet_size = strlen(output);
|
||||
agentSocket.send(DOMAIN_IP, DOMAINSERVER_PORT, output, packet_size);
|
||||
agentList.getAgentSocket()->send(DOMAIN_IP, DOMAINSERVER_PORT, output, packet_size);
|
||||
|
||||
// Ping the agents we can see
|
||||
// pingAgents(&agentSocket);
|
||||
|
@ -765,7 +765,7 @@ void *networkReceive(void *args)
|
|||
sockaddr_in senderAddress;
|
||||
ssize_t bytesReceived;
|
||||
while (true) {
|
||||
if (agentSocket.receive(&senderAddress, (void *)incomingPacket, &bytesReceived)) {
|
||||
if (agentList.getAgentSocket()->receive(&senderAddress, (void *)incomingPacket, &bytesReceived)) {
|
||||
|
||||
packetcount++;
|
||||
bytescount += bytesReceived;
|
||||
|
|
|
@ -8,6 +8,14 @@
|
|||
|
||||
#include "AgentList.h"
|
||||
|
||||
AgentList::AgentList() : agentSocket(AGENT_SOCKET_LISTEN_PORT) {
|
||||
|
||||
}
|
||||
|
||||
UDPSocket * AgentList::getAgentSocket() {
|
||||
return &agentSocket;
|
||||
}
|
||||
|
||||
int AgentList::updateList(char *packetData) {
|
||||
int readAgents = 0;
|
||||
int scannedItems = 0;
|
||||
|
|
|
@ -12,18 +12,22 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "Agent.h"
|
||||
#include "UDPSocket.h"
|
||||
|
||||
const unsigned short AGENT_SOCKET_LISTEN_PORT = 40103;
|
||||
|
||||
class AgentList {
|
||||
public:
|
||||
AgentList();
|
||||
std::vector<Agent> agents;
|
||||
int updateList(char *packetData);
|
||||
|
||||
int processAgentData(char *address, unsigned short port, char *packetData, size_t dataBytes);
|
||||
int broadcastToAgents(char *broadcastData, size_t dataBytes, bool sendToSelf);
|
||||
void pingAgents();
|
||||
UDPSocket* getAgentSocket();
|
||||
private:
|
||||
UDPSocket agentSocket;
|
||||
int addAgent(AgentSocket *publicSocket, AgentSocket *localSocket, char agentType);
|
||||
int indexOfMatchingAgent(AgentSocket *publicSocket, AgentSocket *privateSocket, char agentType);
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ class AgentSocket {
|
|||
AgentSocket(const AgentSocket &otherAgentSocket);
|
||||
AgentSocket& operator=(AgentSocket otherAgentSocket);
|
||||
~AgentSocket();
|
||||
|
||||
|
||||
|
||||
char *address;
|
||||
unsigned short port;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#define MAX_BUFFER_LENGTH_BYTES 1024
|
||||
|
||||
class UDPSocket {
|
||||
public:
|
||||
public:
|
||||
UDPSocket(int listening_port);
|
||||
~UDPSocket();
|
||||
int send(sockaddr_in *destAddress, const void *data, size_t byteLength);
|
||||
|
@ -25,15 +25,6 @@ class UDPSocket {
|
|||
bool receive(sockaddr_in *recvAddress, void *receivedData, ssize_t *receivedBytes);
|
||||
private:
|
||||
int handle;
|
||||
|
||||
UDPSocket(); // private default constructor
|
||||
|
||||
struct AgentData {
|
||||
char * address;
|
||||
int listening_port;
|
||||
};
|
||||
|
||||
AgentData *known_agents;
|
||||
};
|
||||
|
||||
#endif /* defined(__interface__UDPSocket__) */
|
||||
|
|
Loading…
Reference in a new issue