Photon Server and Multithreading

Options
NoelBlakley
edited July 2018 in Photon Server
Hello,

I posted this question on Photon Server's official forum but right now only myself and 1 guest is currently viewing the board so I figured I'd ask the question here too. Here is a link if you'd prefer to answer it there exitgames.com/viewtopic.php?f=5&t=4043, Here is the question: I have a question on PhotonServer's PeerBase class and multithreading. Is it safe to start a short-lifetime thread that will access the send event and disconnect methods of the PeerBase without a lock or am I required to use the lock below. What sort of issues will I run into for the short duration of the lock and is it possible I could deadlock with something under the hood? Any information on how I should go about starting this thread would be great. I don't want to halt execution by Sleeping on the main thread. The reason I'm sleeping though is if I don't sleep it seems to disconnect me before my client can receive the event. This may be because I stop polling the listener for events after disconnection; I don't really want to rewrite that client side. So is there any other way to handle this, is this code below the recommended or do I not need to lock at all?

Please help

I didn't find the right solution from the internet.

References:
https://forum.unity.com/threads/photon-server-and-multithreading.221837/

Thank you

Comments

  • chvetsov
    Options
    hi, @NoelBlakley

    It would be good if your posts would be more nicely formatted.

    if your question is about authentication checks, then I would say that you do not need an extra thread. in our code we setup timer in peer's constructor. when we get auth request this timer is killed. we do setup timer using peers fiber - this.RequestFiber.Schedule(....).

    Same with a disconnect. we send a notification to client schedule call to peers' disconnect method. usually, 200-300 ms is enough. the client gets the notification and either disconnects himself, or we disconnect him

    best,
    ilya