History

Added ping detection between agents

Philip Rosedale committed 13 years ago

Commit a48d9ec1 parent 6f9d2233 files · +69 −9Browse files

Showing the changes to interface/src/main.cpp (1 of 3 files). Show all

Unified · Split

interface/src/main.cpp+36−6
@@ -100,7 +100,7 @@ Cloud cloud(0, // Particles · 99 unmodified lines
100100 false // Wrap
101101 );
102102
103−VoxelSystem voxels(0, box);
103+VoxelSystem voxels(1000, box);
104104
105105 Lattice lattice(160,100);
106106 Finger myFinger(WIDTH, HEIGHT);
@@ -230,6 +230,25 @@ void Timer(int extra) · 123 unmodified lines
230230 int packet_size = strlen(output);
231231 agentSocket.send(DOMAINSERVER_IP, DOMAINSERVER_PORT, output, packet_size);
232232
233+ // Ping the agents we can see
234+ pingAgents(&agentSocket);
235+
236+ if (0) {
237+ // Massive send packet speed test
238+ timeval starttest, endtest;
239+ gettimeofday(&starttest, NULL);
240+ char junk[1000];
241+ junk[0] = 'J';
242+ for (int i = 0; i < 3000; i++)
243+ {
244+ agentSocket.send("192.168.1.38", AGENT_UDP_PORT, junk, 1000);
245+ }
246+ gettimeofday(&endtest, NULL);
247+ float sendTime = diffclock(&starttest, &endtest);
248+ printf("packet test = %4.1f\n", sendTime);
249+ }
250+
251+
233252 // Send a message to ourselves
234253 //char test[]="T";
235254 //agentSocket.send("127.0.0.1", AGENT_UDP_PORT, test, 1);
@@ -520,7 +539,7 @@ void update_pos(float frametime) · 284 unmodified lines
520539 const int MAX_BROADCAST_STRING = 200;
521540 char broadcast_string[MAX_BROADCAST_STRING];
522541 int broadcast_bytes = myHead.getBroadcastData(broadcast_string);
523− broadcast_to_agents(&agentSocket, broadcast_string, broadcast_bytes);
542+ broadcastToAgents(&agentSocket, broadcast_string, broadcast_bytes);
524543
525544 //printf("-> %s\n", broadcast_string);
526545 //dummyHead.recvBroadcastData(broadcast_string, broadcast_bytes);
@@ -773,14 +792,25 @@ void read_network() · 246 unmodified lines
773792 {
774793 sockaddr_in senderAddress;
775794 int bytes_recvd;
776− agentSocket.receive(&senderAddress, (void *)incoming_packet, &bytes_recvd);
777−
778− if (bytes_recvd > 0)
795+ while (agentSocket.receive(&senderAddress, (void *)incoming_packet, &bytes_recvd))
779796 {
780797 packetcount++;
781798 bytescount += bytes_recvd;
782799 // If packet is a Mouse data packet, copy it over
783− if (incoming_packet[0] == 'M') {
800+ if (incoming_packet[0] == 'P') {
801+ //
802+ // Got Ping, reply immediately!
803+ //
804+ printf("Replying to ping!\n");
805+ char reply[] = "R";
806+ agentSocket.send(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port), reply, 1);
807+ } else if (incoming_packet[0] == 'R') {
808+ //
809+ // Got Reply, record as appropriate
810+ //
811+ setAgentPing(inet_ntoa(senderAddress.sin_addr), ntohs(senderAddress.sin_port));
812+
813+ } else if (incoming_packet[0] == 'M') {
784814 //
785815 // mouse location packet
786816 //

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t