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
100 false // Wrap100 false // Wrap
101 );101 );
102 102
103VoxelSystem voxels(0, box);103VoxelSystem voxels(1000, box);
104 104
105Lattice lattice(160,100);105Lattice lattice(160,100);
106Finger myFinger(WIDTH, HEIGHT);106Finger myFinger(WIDTH, HEIGHT);
@@ -230,6 +230,25 @@ void Timer(int extra) · 123 unmodified lines
230 int packet_size = strlen(output);230 int packet_size = strlen(output);
231 agentSocket.send(DOMAINSERVER_IP, DOMAINSERVER_PORT, output, packet_size);231 agentSocket.send(DOMAINSERVER_IP, DOMAINSERVER_PORT, output, packet_size);
232 232
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
233 // Send a message to ourselves252 // Send a message to ourselves
234 //char test[]="T";253 //char test[]="T";
235 //agentSocket.send("127.0.0.1", AGENT_UDP_PORT, test, 1);254 //agentSocket.send("127.0.0.1", AGENT_UDP_PORT, test, 1);
@@ -520,7 +539,7 @@ void update_pos(float frametime) · 284 unmodified lines
520 const int MAX_BROADCAST_STRING = 200;539 const int MAX_BROADCAST_STRING = 200;
521 char broadcast_string[MAX_BROADCAST_STRING];540 char broadcast_string[MAX_BROADCAST_STRING];
522 int broadcast_bytes = myHead.getBroadcastData(broadcast_string);541 int broadcast_bytes = myHead.getBroadcastData(broadcast_string);
523 broadcast_to_agents(&agentSocket, broadcast_string, broadcast_bytes);542 broadcastToAgents(&agentSocket, broadcast_string, broadcast_bytes);
524 543
525 //printf("-> %s\n", broadcast_string);544 //printf("-> %s\n", broadcast_string);
526 //dummyHead.recvBroadcastData(broadcast_string, broadcast_bytes);545 //dummyHead.recvBroadcastData(broadcast_string, broadcast_bytes);
@@ -773,14 +792,25 @@ void read_network() · 246 unmodified lines
773{792{
774 sockaddr_in senderAddress;793 sockaddr_in senderAddress;
775 int bytes_recvd;794 int bytes_recvd;
776 agentSocket.receive(&senderAddress, (void *)incoming_packet, &bytes_recvd);795 while (agentSocket.receive(&senderAddress, (void *)incoming_packet, &bytes_recvd))
777
778 if (bytes_recvd > 0)
779 {796 {
780 packetcount++;797 packetcount++;
781 bytescount += bytes_recvd;798 bytescount += bytes_recvd;
782 // If packet is a Mouse data packet, copy it over 799 // 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') {
784 // 814 //
785 // mouse location packet 815 // mouse location packet
786 //816 //

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