Unclear where to start with rolling a Photon Server solution

Options
Hey guys,

I'm working on a commercial product with a heavy hardware backend sending primitive data to Unity which is essentially being used just for visualization. Our existing implementation is Photon 3 with Lite (which is obsolete now, it seems). We had this outsourced ages ago and never put anymore work into it and the personnel with the knowledge aren't around anymore but we need to sort out some obscure issues we're having with communication and starting to think we need to just write a new implementation from scratch and port to Photon 4.1.x. We don't have a network specialist and I'm the only person with Unity knowledge, tasked to upgrade the existing stuff to the latest photon.

Thats where I need some feedback. We have Photon Control on a workstation with Unity and a separate workstation running some proprietary software which just sends messages over a TCP socket which Photon relays to Unity. This is a local scenario and isn't connected to the internet.

So from starting with the Unity Server SDK where should I start looking to facilitate this scope? I really just need Photon to listen on a port and bounce whatever comes across it over to the Unity client(s). The LoadBalancingAPI and examples seem very robust and over complicated for what we're trying to do, making it a slow process (for me) to find a solution.

Any feedback is appreciated.

Thanks

Comments

  • chvetsov
    Options
    Hi, Lane

    what you need is not really difficult but you should understand some basic concepts.
    here is docs about Photon Server SDK https://doc.photonengine.com/en-us/onpremise/current/getting-started/photon-server-intro

    Please pay attantion to, Photon Server intro page, Basic Concepts and Starting photon in 5 minutes

    Next could be: https://doc.photonengine.com/en-us/onpremise/current/app-framework/an-app-from-scratch

    Alghough Lite is outdated and not supported, basic concepts still same. so i think except hidden bugs communication between client and server might be same

    best,
    ilya
  • Lane
    Lane
    edited April 2017
    Options
    Ilya,

    Thanks, the app-from-scratch really cleared things up for me. I've updated to Photon4 and made a super basic app similar to the example but I keep getting the error `CTCPSocketServer::ReadCompleted - Exception - CTCPStreamProcessor::ProcessDataStream() - Invalid message format:` when the data tool sends TCP messages. This worked in Photon3/Lite although I'm not sure if it is an error due to updating to Photon4 (eg i must change how the data tool sends data (currently just a simple string)) or if I need to handle the messages differently on the app side. I didn't really see anything in the Lite source that cleared this up for me, but maybe I'm missing something.

    Can you shed some light on how to approach the error?

    Thanks,
    Lane
  • chvetsov
    Options
    hi, Lane
    please provide example of how do you send data from client?

    here is some docs about serialization in photon: https://doc.photonengine.com/en-us/onpremise/current/reference/serialization-in-photon

    best,
    ilya
  • Lane
    Options
    I dug around and found in the Lite App there was something added to work as a background client for the Data Tool which creates a new Socket listener outside running inside the Lite App which captures and relays the messages manually. Our Data Tool enqueues messages and makes (standard?) TCP Reads/Writes with strings to communicate and the custom Lite App socket listener seems to manage the messages on its own. For example..

    The Data Tool might send..
    someData!71.75

    The custom socket listener/client inside Lite App does this...
    bytes = new byte[4096];
    int bytesRec = handler.Receive(bytes);
    dataFromRemoteEP += Encoding.ASCII.GetString(bytes, 0, bytesRec);
    string[] dataPoints = dataFromRemoteEP.Split('!');
    dataFromRemoteEP = "";
    
     if (bytes > 0){
             messageObj = new Dictionary<byte, object> { { 1, dataPoints } };
            lpClient.OpCustom(254, messageObj, true);
    <...>
    And in Unity we see Photon sent us something like...

    {(Byte)1=(String[]){someData!71.75}}

    Which we format and parse into a 'data name' and 'data value' and use in Unity.

    This works, but feels like incorrect structure. We can send messages from Unity with OpCustom and a string in the same format that the tool sends them. It's important that the Data Tool is able to communicate with the Unity client bidirectionally. I suppose the questions here are...
    1. Can we bypass this custom socket listener that was put inside Lite? It seems like it is a redundant step since Photon has the ability to connect and communicate clients.
    2. Is it possible to send generic TCP Writes from an application and have Photon pass them to the Unity client if they are formatted correctly for Photon to handle them?
    3. If so, what would a properly formatted string need to look like?
    4. If so, could the Data Tool listen to a port and read messages sent by Photon if we eliminated the custom listener inside Lite?
  • Lane
    Options
    Hmm, I posted a reply but it disappeared.

    I dug into the existing Lite source and found that a custom socket listener was added to run to listen to a port, then relay messages with OpCustom. It seems like this was done to circumvent Photon not parsing the string message being sent to it.

    try { listener.Bind(remoteEP); listener.Listen(5); handler = listener.Accept(); string dataFromRemoteEP = ""; while (true) { bytes = new byte[4096]; int bytesRec = handler.Receive(bytes); dataFromRemoteEP += Encoding.ASCII.GetString(bytes, 0, bytesRec); string[] dataPoints = dataFromRemoteEP.Split('!'); dataFromRemoteEP = ""; if (bytesRec > 0) { messageObj = new Dictionary<byte, object> { { 1, dataPoints } }; lpClient.OpCustom(LiteCodes.GAMEPLAYRAISEEVENT, messageObj, true); }


    Messages being sent from the Data Tool software TCP Write look like someData!71.75 then it goes through the above code and Unity gets it looking like this {(Byte)1=(String[]){someData,71.75}} which we parse and fill variables with. Unity also sends messages back to the software in the same format, just (name)!(value).

    To make messages go the other way it does this...
    public void OnEvent(ExitGames.Client.Photon.EventData eventData) { String full=eventData.ToStringFull(); String[] str = full.Split('='); String[] str3 = str[1].Split(')'); String[] str4 = str3[1].Split('}'); handler.Send(Encoding.UTF8.GetBytes(str4[0])); }

    Can we send strings to Photon in a format it can relay to Unity without using this custom socket listener that was put into Lite? The goal is to use Photon to allow this Data Tool software to Read/Write TCP with Photon being the middleware to Unity. If so, what would a properly formatted string for a TCP write (that photon can read happily) look like?
  • Lane
    Options
    Hmm, editing posts seems to make them disappear?

    I dug into the existing Lite source and found that a custom socket listener was added to run to listen to a port, then relay messages with OpCustom. It seems like this was done to circumvent Photon not parsing the string message being sent to it.

    try { listener.Bind(remoteEP); listener.Listen(5); handler = listener.Accept(); string dataFromRemoteEP = ""; while (true) { bytes = new byte[4096]; int bytesRec = handler.Receive(bytes); dataFromRemoteEP += Encoding.ASCII.GetString(bytes, 0, bytesRec); string[] dataPoints = dataFromRemoteEP.Split('!'); dataFromRemoteEP = ""; if (bytesRec > 0) { messageObj = new Dictionary<byte, object> { { 1, dataPoints } }; lpClient.OpCustom(LiteCodes.GAMEPLAYRAISEEVENT, messageObj, true); }


    Messages being sent from the Data Tool software TCP Write look like someData!71.75 then it goes through the above code and Unity gets it looking like this {(Byte)1=(String[]){someData,71.75}} which we parse and fill variables with. Unity also sends messages back to the software in the same format, just (name)!(value).

    To make messages go the other way it does this...
    public void OnEvent(ExitGames.Client.Photon.EventData eventData) { String full=eventData.ToStringFull(); String[] str = full.Split('='); String[] str3 = str[1].Split(')'); String[] str4 = str3[1].Split('}'); handler.Send(Encoding.UTF8.GetBytes(str4[0])); }

    Can we send strings to Photon in a format it can relay to Unity without using this custom socket listener that was put into Lite? The goal is to use Photon to allow this Data Tool software to Read/Write TCP with Photon being the middleware to Unity. If so, what would a properly formatted string for a TCP write (that photon can read happily) look like?
  • chvetsov
    Options
    if you may modify your data tool software then you could change it so, that it will use photon client lib to connect to photon , if you are not able to do this, then you should leave it as is. photon accepts messages only strictly defined format

    best,
    ilya