Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualTispe

Posted 02 October 2013 - 11:56 AM

Ok, I need some help. On the server side, the event->peer->data member gets overwritten such that all packets looks like they come from the same source. If I connect 3 clients to the server, all packets seems to come from the last ip:port connected!? I thought that Enet filled all event->peer fields during enet_host_service (server, &event, 1000)?

	//Main Loop
	bool loop = true;
	while(loop){
		ENetEvent event;
		/* Wait up to 1000 milliseconds for an event. */
		while (enet_host_service (server, &event, 1000) > 0){
			switch (event.type)    {    
			case ENET_EVENT_TYPE_CONNECT:        
				printf("A new client connected from %x:%u.\n", event.peer->address.host, event.peer->address.port);        
				/* Store any relevant client information here. */
				long long ipandport;
				char buffer[64];
				in_addr addr;
				addr.S_un.S_addr = event.peer->address.host;
				sprintf_s(buffer, "%s:%d", inet_ntoa(addr), event.peer->address.port);
				event.peer->data = buffer;	//Overwritten for all peers????

				ipandport = *((long long*) (&event.peer->address));
				cout << "Registered user: " << ipandport << endl;
				break;    
			case ENET_EVENT_TYPE_RECEIVE:        
				printf("A packet of length %u containing %s was received from %s on channel %u.\n",                
					event.packet->dataLength,                
					event.packet->data,                
					event.peer->data,	//All packets are from same IP:Port???
					event.channelID);        
				/* Clean up the packet now that we're done using it. */
				if(event.packet != NULL){
					enet_packet_destroy (event.packet);
				}
				break;           
			case ENET_EVENT_TYPE_DISCONNECT:        
				printf("%s disconected.\n", event.peer->data);        
				/* Reset the peer's client information. */        
				event.peer -> data = NULL;    
			}
		}
	}

#2Tispe

Posted 02 October 2013 - 11:54 AM

Ok, I need some help. On the server side, the event->peer->data member gets overwritten such that all packets gets the same. If I connect 3 clients to the server, all packets seems to come from the last ip:port connected!? I thought that Enet filled all event->peer fields during enet_host_service (server, &event, 1000)?

	//Main Loop
	bool loop = true;
	while(loop){
		ENetEvent event;
		/* Wait up to 1000 milliseconds for an event. */
		while (enet_host_service (server, &event, 1000) > 0){
			switch (event.type)    {    
			case ENET_EVENT_TYPE_CONNECT:        
				printf("A new client connected from %x:%u.\n", event.peer->address.host, event.peer->address.port);        
				/* Store any relevant client information here. */
				long long ipandport;
				char buffer[64];
				in_addr addr;
				addr.S_un.S_addr = event.peer->address.host;
				sprintf_s(buffer, "%s:%d", inet_ntoa(addr), event.peer->address.port);
				event.peer->data = buffer;	//Overwritten for all peers????

				ipandport = *((long long*) (&event.peer->address));
				cout << "Registered user: " << ipandport << endl;
				break;    
			case ENET_EVENT_TYPE_RECEIVE:        
				printf("A packet of length %u containing %s was received from %s on channel %u.\n",                
					event.packet->dataLength,                
					event.packet->data,                
					event.peer->data,	//All packets are from same IP:Port???
					event.channelID);        
				/* Clean up the packet now that we're done using it. */
				if(event.packet != NULL){
					enet_packet_destroy (event.packet);
				}
				break;           
			case ENET_EVENT_TYPE_DISCONNECT:        
				printf("%s disconected.\n", event.peer->data);        
				/* Reset the peer's client information. */        
				event.peer -> data = NULL;    
			}
		}
	}

#1Tispe

Posted 02 October 2013 - 11:53 AM

Ok, I need some help. On the server side, the event->peer->data member gets overwritten such that all packets gets the same. If I connect 3 clients to the server, all packets seems to come from the last ip:port connected!? I thought that Enet filled all event->peer fields during enet_host_service (server, &event, 1000)?

	//Main Loop
	bool loop = true;
	while(loop){
		ENetEvent event;
		/* Wait up to 1000 milliseconds for an event. */
		while (enet_host_service (server, &event, 1000) > 0){
			switch (event.type)    {    
			case ENET_EVENT_TYPE_CONNECT:        
				printf("A new client connected from %x:%u.\n", event.peer->address.host, event.peer->address.port);        
				/* Store any relevant client information here. */
				long long ipandport;
				char buffer[64];
				in_addr addr;
				addr.S_un.S_addr = event.peer->address.host;
				sprintf_s(buffer, "%s:%d", inet_ntoa(addr), event.peer->address.port);
				event.peer->data = buffer;														//Overwritten for all peers????

				ipandport = *((long long*) (&event.peer->address));
				cout << "Registered user: " << ipandport << endl;
				break;    
			case ENET_EVENT_TYPE_RECEIVE:        
				printf("A packet of length %u containing %s was received from %s on channel %u.\n",                
					event.packet->dataLength,                
					event.packet->data,                
					event.peer->data,															//All packets are from same IP:Port???
					event.channelID);        
				/* Clean up the packet now that we're done using it. */
				if(event.packet != NULL){
					enet_packet_destroy (event.packet);
				}
				break;           
			case ENET_EVENT_TYPE_DISCONNECT:        
				printf("%s disconected.\n", event.peer->data);        
				/* Reset the peer's client information. */        
				event.peer -> data = NULL;    
			}
		}
	}

PARTNERS