Esempio n. 1
0
 private string Send(Protol paramer, bool recv = false)
 {
     try
     {
         string envMessage = JsonConvert.SerializeObject(paramer, Formatting.Indented);
         Debug.Log("send: " + paramer.Code + " msg: " + envMessage);
         sender.Send(AppendLength(Encoding.ASCII.GetBytes(envMessage)));
         if (recv)
         {
             int location = sender.Receive(messageHolder);
             Debug.Log("rcv msg: " + paramer.Code);
             string res = Encoding.ASCII.GetString(messageHolder, 0, location);;
             if (res == "EXIT")
             {
                 init = false;
                 sender.Close();
                 Debug.Log("Socket closed");
             }
             return(res);
         }
         else
         {
             return(string.Empty);
         }
     }
     catch (SocketException e)
     {
         Debug.LogWarning(e.Message);
         return(string.Empty);
     }
 }
Esempio n. 2
0
    private void Send(Protol paramer, bool async)
    {
        string envMessage = JsonConvert.SerializeObject(paramer, Formatting.Indented);

        if (async)
        {
            communicator.Send(envMessage);
        }
        else
        {
            communicator.SendImm(envMessage);
        }
        // Debug.Log("recv: " + paramer.recv);
        if (paramer.recv)
        {
            communicator.Recive();
        }
    }
Esempio n. 3
0
 private void Send(Protol paramer)
 {
     Send(paramer, true);
 }