mas-bandwidth / yojimbo

A network library for client/server games written in C++
BSD 3-Clause "New" or "Revised" License
2.48k stars 242 forks source link

Problem with Unreal #56

Closed shanyang closed 7 years ago

shanyang commented 7 years ago

Hi Glenn, I tried to integrate libyojimbo with unreal engine, after successfuly sending/receiving message with bare windows client to linux server, it's failed doing excactling the same thing in Unreal Engine tutorial scene. I did some network sniffing with Wireshark, it's weird the client side sends 10 UDP packets of 18 bytes payload to server, and server logged with "ignored encrypted packet, no read packet key for this address", any ideas? Here's my code (in Unreal).

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.

#include "physxClient.h"
#include "physxClientGameMode.h"
#include "physxClientHUD.h"
#include "physxClientCharacter.h"
#include "../ThirdParty/libyojimbo/include/yojimbo.h"
#include "../ThirdParty/libyojimbo/include/shared.h"
#include <signal.h>

using namespace yojimbo;

AphysxClientGameMode::AphysxClientGameMode()
    : Super()
{
    // set default pawn class to our Blueprinted character
    static ConstructorHelpers::FClassFinder<APawn> PlayerPawnClassFinder(TEXT("/Game/FirstPersonCPP/Blueprints/FirstPersonCharacter"));
    DefaultPawnClass = PlayerPawnClassFinder.Class;

    // use our custom HUD class
    HUDClass = AphysxClientHUD::StaticClass();
}
double ti = 100.0;

Client* client ;

void AphysxClientGameMode::StartPlay() {
    Super::StartPlay();
    InitializeYojimbo();
    OgameMessageFactory messageFactory(GetDefaultAllocator());
    uint64_t clientId = 1;

    Address clientAddress("0.0.0.0", 6667);
    Address serverAddress("192.168.0.8", 6666);

    ClientServerConfig config;
    config.numChannels = 1;
    config.channel[0].type = CHANNEL_TYPE_UNRELIABLE_UNORDERED;

    client = new Client(GetDefaultAllocator(), clientAddress, config, adapter, ti);

    uint8_t privateKey[KeyBytes];
    memset(privateKey, 0, KeyBytes);
    client->InsecureConnect(privateKey, clientId, serverAddress);
    client->AdvanceTime(ti);
}

void AphysxClientGameMode::Tick(float f) {
    Super::Tick(f);

    const double deltaTime = 0.1;

    JoinMessage* message = (JoinMessage*)(client->CreateMessage(JOIN_MESSAGE));
    message->teamId = 1;
    client->SendMessage(0, message);
    client->SendPackets();
    client->ReceivePackets();
    ti += deltaTime;
    client->AdvanceTime(ti);
    //messageFactory.ReleaseMessage(message);

    yojimbo_sleep(deltaTime);

    return;
}
gafferongames commented 7 years ago

Do the client and the server have the same private key?

gafferongames commented 7 years ago

Also, you don't want to put the yojimbo_sleep in the ClientGameMode::Tick, you want instead to pass in the actual delta time (real time) that has passed since the last call to tick. eg. float f, not 0.1

gafferongames commented 7 years ago

Also, please call:

yojimbo_log_level( YOJIMBO_LOG_LEVEL_DEBUG );

on both client and server and send me both logs.

gafferongames commented 7 years ago

ps. if you compare the debug logs with the working client (external to unreal), vs. the non-working client in unreal, you might be able to spot the difference yourself.

shanyang commented 7 years ago

Hi Glenn, thanks for the reply. I updated full code and recompiled the library, add log to both client and server (have to hack a little since Unreal consumed printf), here are the results:

Client:

[2017.06.27-08.47.32:750][175]LogTemp: connection error. disconnecting client

Server:

server listening on 192.168.0.8:6666

reset encryption manager

server started with 64 client slots

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

ignored encrypted packet. no read packet key for this address

Here's wireshark capture BTW: https://www.dropbox.com/s/i07a6qvou3bf1tt/20170627171217.png?dl=0

and, on both side the key is all set to 0, with pure visual studio c++ project yojimbo works perfectly.

gafferongames commented 7 years ago

Why don't you try different client and server ports? These ports seem like Unreal ports. Maybe that is related... also, there should be more logs on both client and server, did you set the log level to debug? I would expect much more logs to be printed at debug level, especially on the client...

gafferongames commented 7 years ago

The thing that looks weird here is that the client should start, and be sending more packets to the server to negotiate connection than I see in these logs. I think the packets you might be seeing coming in on the server are not from the yojimbo client, but are unreal packets being sent to 6666, unrelated to your client embedded in unreal? This would explain why they are rejected, since the yojimbo client connection handshake has not occured that assigns the client to a slot and sets up the encryption mapping for that client. Try different ports on your client and server and see what happens.

shanyang commented 7 years ago

Hi Glenn, I did set the log level to debug, guess some info directly print to "printf" is missing cause I just hack "yojimbo_printf" to Unreal log system. And I tried different port already, it's pretty the same. I will try to debug lower code to find out what Unreal do with socket connection today.

gafferongames commented 7 years ago

When I set debug log level on server.cpp in yojimbo here is what I get:

started server on port 40000 (insecure)
server listening on 127.0.0.1:40000
reset encryption manager
server started with 64 client slots
server received connection request from 127.0.0.1:49661
server sent connection challenge packet
server received connection response from 127.0.0.1:49661
server accepted client 127.0.0.1:49661 09740048680edc2b in slot 0
[server endpoint] sending packet 0
[server endpoint] sending packet 0 without fragmentation
server sent connection keep alive packet to client 0
[server endpoint] sending packet 1
[server endpoint] sending packet 1 without fragmentation
server received connection payload packet from client 0
server confirmed connection to client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 2
[server endpoint] sending packet 2 without fragmentation
[server endpoint] processing packet 3
[server endpoint] process packet 3 successful
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 3
[server endpoint] sending packet 3 without fragmentation
[server endpoint] processing packet 4
[server endpoint] process packet 4 successful
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 4
[server endpoint] sending packet 4 without fragmentation
[server endpoint] processing packet 5
[server endpoint] process packet 5 successful
[server endpoint] acked packet 0
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 5
[server endpoint] sending packet 5 without fragmentation
[server endpoint] processing packet 6
[server endpoint] process packet 6 successful
[server endpoint] acked packet 1
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 6
[server endpoint] sending packet 6 without fragmentation
[server endpoint] processing packet 7
[server endpoint] process packet 7 successful
[server endpoint] acked packet 2
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 7
[server endpoint] sending packet 7 without fragmentation
[server endpoint] processing packet 8
[server endpoint] process packet 8 successful
[server endpoint] acked packet 3
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 8
[server endpoint] sending packet 8 without fragmentation
[server endpoint] processing packet 9
[server endpoint] process packet 9 successful
[server endpoint] acked packet 4
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 9
[server endpoint] sending packet 9 without fragmentation
[server endpoint] processing packet 10
[server endpoint] process packet 10 successful
[server endpoint] acked packet 5
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 10
[server endpoint] sending packet 10 without fragmentation
[server endpoint] processing packet 11
[server endpoint] process packet 11 successful
[server endpoint] acked packet 6
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 11
[server endpoint] sending packet 11 without fragmentation
[server endpoint] processing packet 12
[server endpoint] process packet 12 successful
[server endpoint] acked packet 7
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 12
[server endpoint] sending packet 12 without fragmentation
[server endpoint] processing packet 13
[server endpoint] process packet 13 successful
[server endpoint] acked packet 8
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 13
[server endpoint] sending packet 13 without fragmentation
[server endpoint] processing packet 14
[server endpoint] process packet 14 successful
[server endpoint] acked packet 9
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 14
[server endpoint] sending packet 14 without fragmentation
[server endpoint] processing packet 15
[server endpoint] process packet 15 successful
[server endpoint] acked packet 10
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 15
[server endpoint] sending packet 15 without fragmentation
[server endpoint] processing packet 16
[server endpoint] process packet 16 successful
[server endpoint] acked packet 11
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 16
[server endpoint] sending packet 16 without fragmentation
[server endpoint] processing packet 17
[server endpoint] process packet 17 successful
[server endpoint] acked packet 12
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 17
[server endpoint] sending packet 17 without fragmentation
[server endpoint] processing packet 18
[server endpoint] process packet 18 successful
[server endpoint] acked packet 13
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 18
[server endpoint] sending packet 18 without fragmentation
[server endpoint] processing packet 19
[server endpoint] process packet 19 successful
[server endpoint] acked packet 14
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 19
[server endpoint] sending packet 19 without fragmentation
[server endpoint] processing packet 20
[server endpoint] process packet 20 successful
[server endpoint] acked packet 15
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 20
[server endpoint] sending packet 20 without fragmentation
[server endpoint] processing packet 21
[server endpoint] process packet 21 successful
[server endpoint] acked packet 16
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 21
[server endpoint] sending packet 21 without fragmentation
[server endpoint] processing packet 22
[server endpoint] process packet 22 successful
[server endpoint] acked packet 17
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 22
[server endpoint] sending packet 22 without fragmentation
[server endpoint] processing packet 23
[server endpoint] process packet 23 successful
[server endpoint] acked packet 18
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 23
[server endpoint] sending packet 23 without fragmentation
[server endpoint] processing packet 24
[server endpoint] process packet 24 successful
[server endpoint] acked packet 19
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 24
[server endpoint] sending packet 24 without fragmentation
[server endpoint] processing packet 25
[server endpoint] process packet 25 successful
[server endpoint] acked packet 20
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 25
[server endpoint] sending packet 25 without fragmentation
[server endpoint] processing packet 26
[server endpoint] process packet 26 successful
[server endpoint] acked packet 21
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 26
[server endpoint] sending packet 26 without fragmentation
[server endpoint] processing packet 27
[server endpoint] process packet 27 successful
[server endpoint] acked packet 22
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 27
[server endpoint] sending packet 27 without fragmentation
[server endpoint] processing packet 28
[server endpoint] process packet 28 successful
[server endpoint] acked packet 23
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 28
[server endpoint] sending packet 28 without fragmentation
[server endpoint] processing packet 29
[server endpoint] process packet 29 successful
[server endpoint] acked packet 24
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 29
[server endpoint] sending packet 29 without fragmentation
[server endpoint] processing packet 30
[server endpoint] process packet 30 successful
[server endpoint] acked packet 25
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 30
[server endpoint] sending packet 30 without fragmentation
[server endpoint] processing packet 31
[server endpoint] process packet 31 successful
[server endpoint] acked packet 26
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 31
[server endpoint] sending packet 31 without fragmentation
[server endpoint] processing packet 32
[server endpoint] process packet 32 successful
[server endpoint] acked packet 27
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 32
[server endpoint] sending packet 32 without fragmentation
[server endpoint] processing packet 33
[server endpoint] process packet 33 successful
[server endpoint] acked packet 28
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 33
[server endpoint] sending packet 33 without fragmentation
[server endpoint] processing packet 34
[server endpoint] process packet 34 successful
[server endpoint] acked packet 29
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 34
[server endpoint] sending packet 34 without fragmentation
[server endpoint] processing packet 35
[server endpoint] process packet 35 successful
[server endpoint] acked packet 30
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 35
[server endpoint] sending packet 35 without fragmentation
[server endpoint] processing packet 36
[server endpoint] process packet 36 successful
[server endpoint] acked packet 31
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 36
[server endpoint] sending packet 36 without fragmentation
[server endpoint] processing packet 37
[server endpoint] process packet 37 successful
[server endpoint] acked packet 32
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 37
[server endpoint] sending packet 37 without fragmentation
[server endpoint] processing packet 38
[server endpoint] process packet 38 successful
[server endpoint] acked packet 33
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 38
[server endpoint] sending packet 38 without fragmentation
[server endpoint] processing packet 39
[server endpoint] process packet 39 successful
[server endpoint] acked packet 34
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 39
[server endpoint] sending packet 39 without fragmentation
[server endpoint] processing packet 40
[server endpoint] process packet 40 successful
[server endpoint] acked packet 35
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 40
[server endpoint] sending packet 40 without fragmentation
[server endpoint] processing packet 41
[server endpoint] process packet 41 successful
[server endpoint] acked packet 36
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 41
[server endpoint] sending packet 41 without fragmentation
[server endpoint] processing packet 42
[server endpoint] process packet 42 successful
[server endpoint] acked packet 37
server received connection payload packet from client 0
server sent connection keep alive packet to client 0
[server endpoint] sending packet 42
[server endpoint] sending packet 42 without fragmentation
[server endpoint] processing packet 43
[server endpoint] process packet 43 successful
[server endpoint] acked packet 38
server received connection payload packet from client 0
server received disconnect packet from client 0
server disconnected client 0
ignored encrypted packet. no read packet key for this address
ignored encrypted packet. no read packet key for this address
ignored encrypted packet. no read packet key for this address
ignored encrypted packet. no read packet key for this address
ignored encrypted packet. no read packet key for this address
ignored encrypted packet. no read packet key for this address
ignored encrypted packet. no read packet key for this address
ignored encrypted packet. no read packet key for this address
ignored encrypted packet. no read packet key for this address

When I set debug log level on client.cpp in yojimbo, here is what I see:

connecting client (insecure)
client id is 09740048680edc2b
client started on port 49661
client connecting to server 127.0.0.1:40000 [1/1]
client changed state from 'disconnected' to 'sending connection request'
client sent connection request packet to server
[client endpoint] sending packet 0
[client endpoint] sending packet 0 without fragmentation
client received connection challenge packet from server
client changed state from 'sending connection request' to 'sending connection response'
[client endpoint] sending packet 1
[client endpoint] sending packet 1 without fragmentation
client sent connection response packet to server
[client endpoint] sending packet 2
[client endpoint] sending packet 2 without fragmentation
client received connection keep alive packet from server
client changed state from 'sending connection response' to 'connected'
client connected to server
[client endpoint] sending packet 3
[client endpoint] sending packet 3 without fragmentation
client received connection keep alive packet from server
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 4
[client endpoint] sending packet 4 without fragmentation
[client endpoint] processing packet 0
[client endpoint] process packet 0 successful
client received connection keep alive packet from server
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 5
[client endpoint] sending packet 5 without fragmentation
[client endpoint] processing packet 1
[client endpoint] process packet 1 successful
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 6
[client endpoint] sending packet 6 without fragmentation
[client endpoint] processing packet 2
[client endpoint] process packet 2 successful
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 7
[client endpoint] sending packet 7 without fragmentation
[client endpoint] processing packet 3
[client endpoint] process packet 3 successful
[client endpoint] acked packet 3
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 8
[client endpoint] sending packet 8 without fragmentation
[client endpoint] processing packet 4
[client endpoint] process packet 4 successful
[client endpoint] acked packet 4
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 9
[client endpoint] sending packet 9 without fragmentation
[client endpoint] processing packet 5
[client endpoint] process packet 5 successful
[client endpoint] acked packet 5
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 10
[client endpoint] sending packet 10 without fragmentation
[client endpoint] processing packet 6
[client endpoint] process packet 6 successful
[client endpoint] acked packet 6
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 11
[client endpoint] sending packet 11 without fragmentation
[client endpoint] processing packet 7
[client endpoint] process packet 7 successful
[client endpoint] acked packet 7
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 12
[client endpoint] sending packet 12 without fragmentation
[client endpoint] processing packet 8
[client endpoint] process packet 8 successful
[client endpoint] acked packet 8
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 13
[client endpoint] sending packet 13 without fragmentation
[client endpoint] processing packet 9
[client endpoint] process packet 9 successful
[client endpoint] acked packet 9
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 14
[client endpoint] sending packet 14 without fragmentation
[client endpoint] processing packet 10
[client endpoint] process packet 10 successful
[client endpoint] acked packet 10
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 15
[client endpoint] sending packet 15 without fragmentation
[client endpoint] processing packet 11
[client endpoint] process packet 11 successful
[client endpoint] acked packet 11
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 16
[client endpoint] sending packet 16 without fragmentation
[client endpoint] processing packet 12
[client endpoint] process packet 12 successful
[client endpoint] acked packet 12
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 17
[client endpoint] sending packet 17 without fragmentation
[client endpoint] processing packet 13
[client endpoint] process packet 13 successful
[client endpoint] acked packet 13
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 18
[client endpoint] sending packet 18 without fragmentation
[client endpoint] processing packet 14
[client endpoint] process packet 14 successful
[client endpoint] acked packet 14
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 19
[client endpoint] sending packet 19 without fragmentation
[client endpoint] processing packet 15
[client endpoint] process packet 15 successful
[client endpoint] acked packet 15
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 20
[client endpoint] sending packet 20 without fragmentation
[client endpoint] processing packet 16
[client endpoint] process packet 16 successful
[client endpoint] acked packet 16
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 21
[client endpoint] sending packet 21 without fragmentation
[client endpoint] processing packet 17
[client endpoint] process packet 17 successful
[client endpoint] acked packet 17
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 22
[client endpoint] sending packet 22 without fragmentation
[client endpoint] processing packet 18
[client endpoint] process packet 18 successful
[client endpoint] acked packet 18
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 23
[client endpoint] sending packet 23 without fragmentation
[client endpoint] processing packet 19
[client endpoint] process packet 19 successful
[client endpoint] acked packet 19
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 24
[client endpoint] sending packet 24 without fragmentation
[client endpoint] processing packet 20
[client endpoint] process packet 20 successful
[client endpoint] acked packet 20
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 25
[client endpoint] sending packet 25 without fragmentation
[client endpoint] processing packet 21
[client endpoint] process packet 21 successful
[client endpoint] acked packet 21
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 26
[client endpoint] sending packet 26 without fragmentation
[client endpoint] processing packet 22
[client endpoint] process packet 22 successful
[client endpoint] acked packet 22
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 27
[client endpoint] sending packet 27 without fragmentation
[client endpoint] processing packet 23
[client endpoint] process packet 23 successful
[client endpoint] acked packet 23
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 28
[client endpoint] sending packet 28 without fragmentation
[client endpoint] processing packet 24
[client endpoint] process packet 24 successful
[client endpoint] acked packet 24
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 29
[client endpoint] sending packet 29 without fragmentation
[client endpoint] processing packet 25
[client endpoint] process packet 25 successful
[client endpoint] acked packet 25
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 30
[client endpoint] sending packet 30 without fragmentation
[client endpoint] processing packet 26
[client endpoint] process packet 26 successful
[client endpoint] acked packet 26
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 31
[client endpoint] sending packet 31 without fragmentation
[client endpoint] processing packet 27
[client endpoint] process packet 27 successful
[client endpoint] acked packet 27
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 32
[client endpoint] sending packet 32 without fragmentation
[client endpoint] processing packet 28
[client endpoint] process packet 28 successful
[client endpoint] acked packet 28
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 33
[client endpoint] sending packet 33 without fragmentation
[client endpoint] processing packet 29
[client endpoint] process packet 29 successful
[client endpoint] acked packet 29
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 34
[client endpoint] sending packet 34 without fragmentation
[client endpoint] processing packet 30
[client endpoint] process packet 30 successful
[client endpoint] acked packet 30
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 35
[client endpoint] sending packet 35 without fragmentation
[client endpoint] processing packet 31
[client endpoint] process packet 31 successful
[client endpoint] acked packet 31
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 36
[client endpoint] sending packet 36 without fragmentation
[client endpoint] processing packet 32
[client endpoint] process packet 32 successful
[client endpoint] acked packet 32
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 37
[client endpoint] sending packet 37 without fragmentation
[client endpoint] processing packet 33
[client endpoint] process packet 33 successful
[client endpoint] acked packet 33
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 38
[client endpoint] sending packet 38 without fragmentation
[client endpoint] processing packet 34
[client endpoint] process packet 34 successful
[client endpoint] acked packet 34
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 39
[client endpoint] sending packet 39 without fragmentation
[client endpoint] processing packet 35
[client endpoint] process packet 35 successful
[client endpoint] acked packet 35
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 40
[client endpoint] sending packet 40 without fragmentation
[client endpoint] processing packet 36
[client endpoint] process packet 36 successful
[client endpoint] acked packet 36
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 41
[client endpoint] sending packet 41 without fragmentation
[client endpoint] processing packet 37
[client endpoint] process packet 37 successful
[client endpoint] acked packet 37
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 42
[client endpoint] sending packet 42 without fragmentation
[client endpoint] processing packet 38
[client endpoint] process packet 38 successful
[client endpoint] acked packet 38
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 43
[client endpoint] sending packet 43 without fragmentation
[client endpoint] processing packet 39
[client endpoint] process packet 39 successful
[client endpoint] acked packet 39
client received connection payload packet from server
client received connection keep alive packet from server
[client endpoint] sending packet 44
[client endpoint] sending packet 44 without fragmentation
[client endpoint] processing packet 40
[client endpoint] process packet 40 successful
[client endpoint] acked packet 40
client received connection payload packet from server
client received connection keep alive packet from server
^Cclient disconnected
client sent disconnect packets to server
client sent disconnect packet 0
client sent disconnect packet 1
client sent disconnect packet 2
client sent disconnect packet 3
client sent disconnect packet 4
client sent disconnect packet 5
client sent disconnect packet 6
client sent disconnect packet 7
client sent disconnect packet 8
client sent disconnect packet 9
client changed state from 'connected' to 'disconnected'

I would expect to see at least these lines on your client if it had the debug level properly set:

connecting client (insecure)
client id is 09740048680edc2b
client started on port 49661
client connecting to server 127.0.0.1:40000 [1/1]
client changed state from 'disconnected' to 'sending connection request'
client sent connection request packet to server

But I don't, so I think the client either doesn't have the log level set, or something really wrong with your code.

shanyang commented 7 years ago

That's what I saw when I connect from pure c++ client to my server.

gafferongames commented 7 years ago

I'm not sure what's wrong with the logs, but that's not a full output from a client with debug log level set. Something is wrong on your side, whether it's how you've hooked up to logs, or something with how you've adapted the code to work within Unreal.

gafferongames commented 7 years ago

If you post your whole cpp/h file with the integration into Unreal, as a gist, I can at least look at it and make some suggestions for you. For example, you are calling yojimbo_sleep inside an update function, you definitely don't want to do that inside unreal... there are other errors that may be in there.

gafferongames commented 7 years ago

You also don't need to call this:

    client->AdvanceTime(ti);

After you create the client. That's redundant. You also don't need to start ti = 100.0f, that's just something I do in the client.cpp test program because it catches a class of bugs that only show up when time is far away from 0.0.

gafferongames commented 7 years ago

Also, inside your Tick function, you are passing in a fixed tick of 0.1 seconds. Instead, what you want to do is to pass in the float f for the tick, which is the actual delta time from unreal engine. This is what client->AdvanceTime wants, the actual time that has passed since the last frame...

gafferongames commented 7 years ago

Your tick function should look like this:

void AphysxClientGameMode::Tick( float deltaTime ) 
{
    Super::Tick( deltaTime );
    JoinMessage * message = (JoinMessage*) client->CreateMessage( JOIN_MESSAGE );
    message->teamId = 1;
    client->SendMessage( 0, message );
    client->SendPackets();
    client->ReceivePackets();
    ti += deltaTime;
    client->AdvanceTime(ti);
}
shanyang commented 7 years ago

I fixed the tick problem since yesterday. here's the gist: https://gist.github.com/shanyang/e6e400e71aa9aead494accf742c1b011

gafferongames commented 7 years ago

Here are my adjustments, nothing too significant:

https://gist.github.com/gafferongames/94fe2a6effcaf8dd9606a0c7295d8d99

gafferongames commented 7 years ago

What happens if you run this just by itself (without a server), what do you see?

Are you 100% certain that AphysxClientGameMode::StartPlay() is getting called?

gafferongames commented 7 years ago

I mean it almost seems to me like you haven't started the client, and the connection errors out (probably because the message send queue gets full...). this could explain why less logs are showing up than expected on the client. i dunno...

shanyang commented 7 years ago

I'm pretty sure it's called. I'm trying to find a way to make Unreal output the log now.

shanyang commented 7 years ago

Hi Glenn, I find out that client->CreateMessage has an assert failure, seems that my message type defination has not been set correctly (the m_numTypes is a ridiculous number), any idea on this?

gafferongames commented 7 years ago

Have you registered a message factory via the adapter class? see shared.h for an example

shanyang commented 7 years ago

Think I did, here's my shared.h: https://gist.github.com/shanyang/ba152bdbbd10b7ee218f36ed32ddca70

gafferongames commented 7 years ago

Yeah looks OK to me.

gafferongames commented 7 years ago

Can you please set a breakpoint and make sure that the StartPlay is actually getting called? Hunch.

gafferongames commented 7 years ago

Because if it's not, that would totally explain everything

shanyang commented 7 years ago

I stepped debug once again, it looks fine.

gafferongames commented 7 years ago

Try this:

void AphysxClientGameMode::Tick( float deltaTime ) 
{
    Super::Tick( deltaTime );
    client->ReceivePackets();
        if ( client->IsConnected() )
        {
            JoinMessage * message = (JoinMessage*) client->CreateMessage( JOIN_MESSAGE );
            message->teamId = 1;
            client->SendMessage( 0, message );
        }
    client->SendPackets();
    ti += deltaTime;
    client->AdvanceTime(ti);
}
gafferongames commented 7 years ago

Run through the debugger with a breakpoint at the start of Client::InsecureConnect, and at the start of client::CreateMessage, take a screenshot of the watch window with the this pointer expanded so I can see the content of client variables @ each point. The errors you are seeing make no sense, and indicate objects that are not being properly constructed or initialized.

gafferongames commented 7 years ago

ps. Are you building in debug build? If not, you should be. You want all the yojimbo_assert code to be active, otherwise you're going to see weird shit when it runs past a fatal error...

shanyang commented 7 years ago

Yes, I built yojimbo in debug mode. I have to change build option: c/c++ -> code generation -> runtime to /MD ( instead of original /MTd I guess), or it cannot work with Unreal code.

shanyang commented 7 years ago

And do you mean breakpoint at beginning of client::CreateMessage?

gafferongames commented 7 years ago

Yes, I want to see the state of the client object when connect is called, and when CreateMessage is called.

gafferongames commented 7 years ago

Can you just package up your project in a way that I could build it with Unreal to see what's going on. I figure that will be much faster than trying to remote debug like this.

gafferongames commented 7 years ago

Sorry, paid work has taken priority over this. I'm going to try to look at it this weekend for you. -- cheers

shanyang commented 7 years ago

No problem, thanks.

2017-07-07 9:52 GMT+08:00 Glenn Fiedler notifications@github.com:

Sorry, paid work has taken priority over this. I'm going to try to look at it this weekend for you. -- cheers

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/networkprotocol/yojimbo/issues/56#issuecomment-313565887, or mute the thread https://github.com/notifications/unsubscribe-auth/AEVddO42QGzgJPIFGgSYC7bcGOakC-Aqks5sLY9FgaJpZM4OFIrW .

shanyang commented 7 years ago

Hi Glenn, How's the testing going?

2017-07-07 13:20 GMT+08:00 Shawn Yang battlefly@gmail.com:

No problem, thanks.

2017-07-07 9:52 GMT+08:00 Glenn Fiedler notifications@github.com:

Sorry, paid work has taken priority over this. I'm going to try to look at it this weekend for you. -- cheers

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/networkprotocol/yojimbo/issues/56#issuecomment-313565887, or mute the thread https://github.com/notifications/unsubscribe-auth/AEVddO42QGzgJPIFGgSYC7bcGOakC-Aqks5sLY9FgaJpZM4OFIrW .

gafferongames commented 7 years ago

Sorry, I should have some time to look at this tomorrow. Been super busy lately.

gafferongames commented 7 years ago

Looking at this now

gafferongames commented 7 years ago

Works for me

#include "YojimboComponent.h"
#include <EngineGlobals.h>
#include <Runtime/Engine/Classes/Engine/Engine.h>
#include "C:/Users/Glenn Fiedler/Documents/Unreal Projects/YojimboTest/Yojimbo/yojimbo.h"
#include "C:/Users/Glenn Fiedler/Documents/Unreal Projects/YojimboTest/Yojimbo/shared.h"

using namespace yojimbo;

int yojimbo_printf_function( const char * format, ... )
{
    char buffer[4*1024];
    va_list args;
    va_start( args, format );
    vsprintf_s( buffer, format, args );
    va_end( args );
    int length = strlen( buffer );
    if ( buffer[length-1] == '\n' )
    {
        buffer[length-1] = '\0';
    }
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, UTF8_TO_TCHAR( buffer ) );
    return 0;
}

UYojimboComponent::UYojimboComponent()
{
    PrimaryComponentTick.bCanEverTick = true;
}

Client * client = NULL;
double clientTime = 0.0;

void UYojimboComponent::BeginPlay()
{
    Super::BeginPlay();
    yojimbo_log_level( YOJIMBO_LOG_LEVEL_DEBUG );
    yojimbo_set_printf_function( yojimbo_printf_function );
    InitializeYojimbo();
    yojimbo_printf( YOJIMBO_LOG_LEVEL_INFO, "connecting client (insecure)\n" );
    uint64_t clientId = 0;
    random_bytes( (uint8_t*) &clientId, 8 );
    ClientServerConfig config;
    client = new Client( GetDefaultAllocator(), Address("0.0.0.0"), config, adapter, clientTime );
    Address serverAddress( "127.0.0.1", ServerPort );
    uint8_t privateKey[KeyBytes];
    memset( privateKey, 0, KeyBytes );
    client->InsecureConnect( privateKey, clientId, serverAddress );
}

void UYojimboComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction )
{
    Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
    client->SendPackets();
    client->ReceivePackets();
    client->AdvanceTime( clientTime );
    clientTime += DeltaTime;
}
shanyang commented 7 years ago

OK, I will try, thanks.

2017-07-14 4:43 GMT+08:00 Glenn Fiedler notifications@github.com:

Works for me

`#include "YojimboComponent.h"

include

include <Runtime/Engine/Classes/Engine/Engine.h>

include "C:/Users/Glenn Fiedler/Documents/Unreal

Projects/YojimboTest/Yojimbo/yojimbo.h"

include "C:/Users/Glenn Fiedler/Documents/Unreal

Projects/YojimboTest/Yojimbo/shared.h"

using namespace yojimbo;

int yojimbo_printf_function( const char format, ... ) { char buffer[41024]; va_list args; va_start( args, format ); vsprintf_s( buffer, format, args ); va_end( args ); int length = strlen( buffer ); if ( buffer[length-1] == '\n' ) { buffer[length-1] = '\0'; } GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, UTF8_TO_TCHAR( buffer ) ); return 0; }

UYojimboComponent::UYojimboComponent() { PrimaryComponentTick.bCanEverTick = true;

// ...

}

Client * client = NULL; double clientTime = 0.0;

void UYojimboComponent::BeginPlay() { Super::BeginPlay();

yojimbo_log_level( YOJIMBO_LOG_LEVEL_DEBUG );

yojimbo_set_printf_function( yojimbo_printf_function );

InitializeYojimbo();

yojimbo_printf( YOJIMBO_LOG_LEVEL_INFO, "connecting client (insecure)\n" );

uint64_t clientId = 0; random_bytes( (uint8_t*) &clientId, 8 ); printf( "client id is %.16" PRIx64 "\n", clientId );

ClientServerConfig config;

client = new Client( GetDefaultAllocator(), Address("0.0.0.0"), config, adapter, clientTime );

Address serverAddress( "127.0.0.1", ServerPort );

uint8_t privateKey[KeyBytes]; memset( privateKey, 0, KeyBytes );

client->InsecureConnect( privateKey, clientId, serverAddress );

}

void UYojimboComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction ) { Super::TickComponent( DeltaTime, TickType, ThisTickFunction );

client->SendPackets();

client->ReceivePackets();

client->AdvanceTime( clientTime );

clientTime += DeltaTime;

} `

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/networkprotocol/yojimbo/issues/56#issuecomment-315196224, or mute the thread https://github.com/notifications/unsubscribe-auth/AEVddIPoJ2n4uz65WFIdUELbtR6CSkciks5sNoFagaJpZM4OFIrW .