Author Topic: UDP Proxy Forwarding success but connection failure  (Read 22292 times)

Thormidable

  • Not-a-newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
UDP Proxy Forwarding success but connection failure
« on: September 07, 2012, 04:38:18 AM »
Hi,
   I've only been using RakNet for a few weeks and have been implementing network code for my current RTS project. I have working code for LAN and NAT Traversal code, which seems to work perfectly. I'm running a deterministic/time step synchronised system for my RTS and have found that there is a problem with time synchronisation over the internet. I'm thinking this is an error in my algorithm, but am out of the office and currently have one system to test on. As such I was going to force the connections from my system through a UDP proxy server to simulate the increased packet delay. This is worth implementing at some point so I'd prefer to get this working rather than artificially introduce packet delay.

I'm running my game server and UDP Proxy server on a single static IP Server online.

I get a Call to OnForwardingSuccess() on the system which initiates Forwarding.
I get a Call on OnForwardingNotification() on the other system.

I Call Connect on both systems with the proxyIP and Proxyport handed to me by the function call.
Connection Code on both systems:
Code: [Select]
void cUDPProxyBase::OnForwardingSuccess (const char *proxyIPAddress, unsigned short proxyPort, SystemAddress proxyCoordinator, SystemAddress sourceAddress, SystemAddress targetAddress, RakNetGUID targetGuid, RakNet::UDPProxyClient *proxyClientPlugin)
{
printf("Forwarding Successful\n");
cNetworkBase::mpPeer->Connect(proxyIPAddress,proxyPort,0,0);
};

void cUDPProxyBase::OnForwardingNotification (const char *proxyIPAddress, unsigned short proxyPort, SystemAddress proxyCoordinator, SystemAddress sourceAddress, SystemAddress targetAddress, RakNetGUID targetGuid, RakNet::UDPProxyClient *proxyClientPlugin)
{
printf("Another User has Connected to this instance through UDP Proxy Server\n");
cNetworkBase::mpPeer->Connect(proxyIPAddress,proxyPort,0,0);
};

I then always get a ID_CONNECTION_ATTEMPT_FAILED signal after a few seconds. I've got ample ports open (20) on the server for the UDP Server to use.

End Output from Instance trying to initiate forwarding:
Code: [Select]
Creating cCamera::cCamera()
Setting up cCollisionHandler
Calling cKernel::Update to start the main loop
Entering cKernel::Update
cLightHandler::SetupLights
Load Settings File ../Media/Settings/HostData.txt
Add String : HostIPAddress : 127.0.0.1
Add Int : HostPort : 9004
Add String : GameServerIP : 82.113.149.148
Add Int : GameServerPort : 9001
Add String : UDPProxyServerIP : 82.113.149.148
Add Int : UDPProxyServerPort : 9002
Host IP:127.0.0.1
Host Port:9004
Game Server Connected
Connect to Proxy Server
Proxy Server Connected
UDP Forward to New Client 4082999227
Forwarding Successful
Connection Attempt Failure

Output from System which does not initiate Forwarding:
Code: [Select]
Creating cCamera::cCamera()
Setting up cCollisionHandler
Calling cKernel::Update to start the main loop
Entering cKernel::Update
cLightHandler::SetupLights
Load Settings File ../Media/Settings/HostData.txt
Add String : HostIPAddress : 127.0.0.1
Add Int : HostPort : 9004
Add String : GameServerIP : 82.113.149.148
Add Int : GameServerPort : 9001
Add String : UDPProxyServerIP : 82.113.149.148
Add Int : UDPProxyServerPort : 9002
Host IP:127.0.0.1
Host Port:9004
Connection Accepted
Game Server Connected
Connect to Proxy Server
Connection Accepted
Proxy Server Connected
Game Selected. Start Connection
New Connection:0
Another User has Connected to this instance through UDP Proxy Server
UDP Proxy Server Forwarding In progress
Connection Attempt Failure

(Host IP and Host Port are for user settings loaded for use with LAN Connections)

Server Code:
Code: [Select]
cUDPProxyServer::cUDPProxyServer(uint16 liPort,uint16 liConnections)
{
miConnected=0;
    miChannels=liConnections;

mpPeer=RakPeerInterface::GetInstance();
SocketDescriptor lcSD(liPort,0);
    mpPeer->Startup(miChannels*2,&lcSD, 1);
    mpPeer->SetMaximumIncomingConnections(miChannels);

    mpPeer->AttachPlugin(&mcUDPProxyServer);
mpPeer->AttachPlugin(&mcUDPProxyCoordinator);
mcUDPProxyServer.SetResultHandler(&mcResults);

mcUDPProxyCoordinator.SetRemoteLoginPassword(COORDINATOR_PASSWORD);
mcUDPProxyServer.LoginToCoordinator(COORDINATOR_PASSWORD, mpPeer->GetInternalID(UNASSIGNED_SYSTEM_ADDRESS));

};

void cUDPProxyServer::ReceivePackets()
{
mpPacket=mpPeer->Receive();
while(mpPacket)
{

switch(GetPacketIdentifier(mpPacket))
        {
        case ID_NEW_INCOMING_CONNECTION:
{
++miConnected;
printf("New Connection : %u Connected\n",miConnected);
}
            break;

case ID_CONNECTION_LOST:
case ID_DISCONNECTION_NOTIFICATION:
        case ID_REMOTE_DISCONNECTION_NOTIFICATION:
{
--miConnected;
printf("Disconnection : %u remain\n",miConnected);
} break;

default:
{
printf("Another Packet\n");
}
            break;
        };

mpPeer->DeallocatePacket(mpPacket);
mpPacket=mpPeer->Receive();
}

mcUDPProxyServer.Update();
};

cMyUDPResult::cMyUDPResult()
{

};

void cMyUDPResult::OnLoginSuccess (RakString usedPassword, UDPProxyServer *proxyServerPlugin)
{
printf("New Login\n");
};
void cMyUDPResult::OnAlreadyLoggedIn (RakString usedPassword, UDPProxyServer *proxyServerPlugin)
{
printf("Client Already Logged in\n");
};
void cMyUDPResult::OnNoPasswordSet (RakString usedPassword, UDPProxyServer *proxyServerPlugin)
{
printf("Password Error. No Password\n");
};
void cMyUDPResult::OnWrongPassword (RakString usedPassword, UDPProxyServer *proxyServerPlugin)
{
printf("Password Error. Wrong Password\n");
};

Am I correct in Trying to connect from both ends following Forwarding initiation?
Am I using the correct IP and Port values?
Do I need to do UPNP for UDP Proxy to work?
Is there something I could be doing wrong (a function call I'm missing etc.) (Not calling udpProxyForwarder::Update() or similar)?
I've tried a range of options, including initiating Forwarding from both sides and connecting from a single side.

Any advice would be greatly appreciated.

Rak'kar

  • Administrator
  • Hero Member
  • *****
  • Posts: 6895
  • Karma: 291
    • View Profile
    • RakNet
Re: UDP Proxy Forwarding success but connection failure
« Reply #1 on: September 08, 2012, 10:37:31 AM »
You do not need to call connect from OnForwardingNotification(). But I don't see any real problems with your code. Can you try updating to the current version? I made some fixes to UDPForwarder and UDPProxyServer/UDPProxyClient not long ago.

Thormidable

  • Not-a-newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: UDP Proxy Forwarding success but connection failure
« Reply #2 on: September 09, 2012, 08:34:30 AM »
Thank you for the reply.

I'll update to the latest version and try again. Just wanted to make sure I hadn't missed something.

ppparkje

  • Not-a-newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: UDP Proxy Forwarding success but connection failure
« Reply #3 on: June 30, 2014, 07:17:52 AM »
I have just same problem now.

Client which received proxy address and port cannot connect to server with them.

The thing I know is that the coordinator and proxy server are in same process and coordinator only opened one port. I think it blocks packets from other ports including proxy port.

Any ideas??