Exception - CENETPeerBase

Options
ymlyjq
edited July 2013 in Photon Server
first ,i found two pages like this ,but a little diffent from my;

http://forum.exitgames.com/viewtopic.php?f=10&t=1516&p=7058&hilit=CENetPeerBase#p7058
> in this case , i read something , cannt use my peer whith diffent thread ???!! if this is true , oh mygod, god god....
for example, client peer is a thread, and one peer want to read other peer'info how can i do ?? only put all user data to a dictionary ,and when use ,get from dictionary ???

http://forum.exitgames.com/viewtopic.php?f=5&t=2405
>yes ,i use 3.2.10.4248

my problem here :
    14628: 00:24:27.638 - 000000000AC758C0: id = 16591 [0] disconnected due to exception 14628: 00:24:27.638 - CENetThreadPool::Process - Exception - CENetPeerBase::HandleIncomingCommands() - PeerAppSelection()- Init: Unexpected message length, need at least 40 bytes, got: 26 : id = 16591 [0] Datagram: 40 CF 00 02 00 00 04 3B 27 3D 89 2D 01 FF 00 04 00 00 00 14 00 00 00 00 00 00 00 00 15 64 25 99 07 00 00 04 00 00 00 2A 00 00 00 01 00 00 00 01 F3 02 FD 00 03 F5 68 00 02 62 01 69 00 01 AD D0 62 02 62 F7 F4 62 87 F6 62 02 - @......;'=.-.................d%........*..............h..b.i....b.b..b..b. from: 221.131.128.206:60588 on: 115.238.231.12:5055 14628: 02:03:17.651 - 0000000015C0F8B0: id = 18429 [0] disconnected due to exception 12396: 02:03:17.651 - CENetThreadPool::Process - Exception - CENetPeerBase::HandleIncomingCommands() - CENetPeerBase::HandleIncomingCommands()- Unexpected: id = 18429 [0] Command length: 62914580 is either zero, or more than available data: 20 : id = 18429 [0] Datagram: 47 FD 00 02 00 00 E5 75 35 70 4C 73 01 FF 00 04 00 00 00 14 00 00 00 00 00 00 00 18 15 BE A0 84 01 04 00 04 03 C0 00 14 00 00 00 00 00 00 00 4A 15 BE A2 2A - G......u5pLs...................................J...* from: 119.162.37.204:40961 on: 101.64.178.2:5055

yes ,i own my manager all peer like :
[code2=csharp]public bool AddPeer(int RoleID,string RoleName,LitePeer peer)
{
if (RoleID == -1) return false;
if (RoleName == null || RoleName == string.Empty) return false;
mutPeer.WaitOne();
if (m_PeerIDList.ContainsKey(RoleID))
{
m_PeerIDList.Remove(RoleID);
}
if (m_PeerNameList.ContainsKey(RoleName))
{
m_PeerNameList.Remove(RoleName);
}

m_PeerIDList[RoleID] = peer;
m_PeerNameList[RoleName] = peer;
mutPeer.ReleaseMutex();
return true;
}[/code2]
and mybe use like this
[code2=csharp]if (peer1 != null)
{
peer1.m_MatchStatus = MatchStatus.MatchStatus_Waiting;
peer1.nMatchCopyId = copyId;
}
if (peer2 != null)
{
peer2.m_MatchStatus = MatchStatus.MatchStatus_Waiting;
peer2.nMatchCopyId = copyId;
}[/code2]
any thing wrong?

i know some time peer1 is null but alse i use peer ,this problem cant call up problem ,i think;

Comments

  • General advice about multi-threading in Photon:

    Photon makes use of message passing principles to synchronize access to Peers etc.: https://code.google.com/p/retlang/

    In short: each peer has one fiber, each fiber is backed up by one thread, and all methods on that peer that needs to be synchronized should be enqueued / executed on the fiber.

    You can also add fibers to your own classes and execute or schedule actions there, like this:

    [code2=csharp]public class NPC
    {
    private PoolFiber fiber = new PoolFiber();

    public NPC()
    {
    fiber.Start();
    fiber.ScheduleOnInterval(Regenerate(), 2000, 2000);
    }

    public void Regenerate()
    {
    // check stats & send event, if required
    }
    }[/code2]


    Only one method at a time is executed on the fiber, and all methods are executed in the same order as they were enqueued, so if you use that approach, you don't need your own locking etc. - it should simplify your code a lot and you will get rid of your threading / lock problems.

    That being said - the exceptions MIGHT happen because you try to write to your peer from different threads simultaneously, but there might also be other reasons... we've also made a fix in that area for the next release of Photon Server SDK.
    If you have a test case where you can reproduce the bug, please send us a simple (!) sample and we could use that to analyze / fix the issue.
  • ymlyjq
    Options
    1 question :
    > photon 's raiseEvent , only used to publishEvent ? if not what 's other using for ?
    i use raiseEvent for operation command , for example, like "but item" " drop item" "get money" also and "move sync" , the diffent is
    sendGroup = ReceiverGroup.MasterClient; or sendGroup = ReceiverGroup.Others
    and other command like "get info " "enter scene" "createroom " "enter room " or other info from database operation ....

    2 question:

    about use fiber in peer,i cant understand ....

    i think , fiber like a queue, when put e in to it,,, it deal by order...

    but , are you sure it is usefull for peer's data using ??

    here "peer's data " means user data like "name " "level " "money" "exp" "item" etc....

    i do not know how to use fiber like you say to use this data...

    for example. one thread ask "up the level" , from level 1 to 2 , and other thread check if the level == 2 to can do something ..

    in these two command , how can i use fiber to do ?

    i know peerbase has one poolfiber and it can be called [code2=csharp]public IFiber RequestFiber()[/code2]

    >> command 1 : up the level
    >> command 2 : check the level to do something

    yes , can use
    [code2=csharp]protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)[/code2]

    but , if iwant do the other command : " get other peer data ,etc get other user's level ,..." ,in one room ,is ok, can do like

    [code2=csharp]//Actor actor;
    actor.Peer.RequestFiber.Enqueue();[/code2]

    but , in world , no in one room , how can i use fiber to do ??

    and can you give me a sample code ?

    [code2=csharp]foreach (RoleMatchInfo info in listInfo)
    {
    if (info.peer != null)
    {
    info.peer.m_MatchStatus = MatchStatus.MatchStatus_None;
    info.peer.nMatchCopyId = 0;
    info.peer.nReadyIndex = -1;
    }
    }[/code2]

    how can i use fiber to improve my code up?

    thanks