コード例 #1
0
 /// <summary>
 /// Invoke a call over the MessageSentCallback reference.<b>If the reference is null, nothing is performed at all.</b> Once the method is invoked the callback reference is set to null.
 /// </summary>
 /// <param name="caller"></param>
 /// <param name="arg"></param>
 public void MessageSent(NetworkEntity caller, object arg)
 {
     if (this.messageSentCallback != null)
     {
         this.messageSentCallback(caller, arg);
         this.messageSentCallback = null;
     }
 }
コード例 #2
0
ファイル: MessageIO.cs プロジェクト: fm107/WebTorrent
 public SendMessageState Init(Socket socket, byte[] buffer,
                              int offset, int count, object state, MessageSentCallback callback)
 {
     Socket   = socket;
     Buffer   = buffer;
     Offset   = offset;
     Count    = count;
     State    = state;
     Callback = callback;
     return(this);
 }
コード例 #3
0
ファイル: MessageIO.cs プロジェクト: fm107/WebTorrent
        public static void SendMessage(Socket socket, PeerMessage message, object state, MessageSentCallback callback)
        {
            var buffer = message.ToBytes();
            var data   = SendCache.Get().Init(socket, buffer, 0, buffer.Length, state, callback);

            SendMessageBase(data);
        }
コード例 #4
0
ファイル: MessageIO.cs プロジェクト: NewFuture/BitTorrent
 public static void SendMessage(Socket socket, PeerMessage message, object state, MessageSentCallback callback)
 {
     byte[] buffer = message.ToBytes();
     SendMessageState data = SendCache.Get().Init(socket, buffer, 0, buffer.Length, state, callback);
     SendMessageBase(data);
 }
コード例 #5
0
ファイル: MessageIO.cs プロジェクト: NewFuture/BitTorrent
 public SendMessageState Init(Socket socket, byte[] buffer,
                              int offset, int count, object state, MessageSentCallback callback)
 {
     Socket = socket;
     Buffer = buffer;
     Offset = offset;
     Count = count;
     State = state;
     Callback = callback;
     return this;
 }
コード例 #6
0
 public void SendMessage(MessageInfo m, MessageSentCallback success, MessageSendingError failure, NoConnectionCallback noconnection)
 {
     StartCoroutine(SendMessageCoroutine(m, success, failure, noconnection));
 }
コード例 #7
0
    public IEnumerator SendMessageCoroutine(MessageInfo m, MessageSentCallback success, MessageSendingError failure, NoConnectionCallback noconnection)
    {
        WWWForm form = new WWWForm();

        form.AddField("recipientId", m.recipient);
        form.AddField("title", m.title);
        form.AddField("messageBody", m.body);
        if (m.replyTo != null)
        {
            form.AddField("replyTo", m.replyTo);
        }

        bool hacked = m_UserManager.CurrentHackedUser != null;

        UnityWebRequest request;

        if (hacked)
        {
            form.AddField("targetId", m_UserManager.CurrentHackedUser);
            request = UnityWebRequest.Post(Constants.serverAddress + "api/hack/messages", form);
        }
        else
        {
            request = UnityWebRequest.Post(Constants.serverAddress + "api/messages", form);
        }

        m_UserManager.SetCurrentUserAuthorization(request);

        yield return(request.SendWebRequest());

        while (!request.isDone)
        {
            yield return(new WaitForEndOfFrame());
        }

        if (request.isNetworkError)
        {
            Debug.Log("Network error: Cannot send message: " + request.error + ", Code = " + request.responseCode);
            if (noconnection != null)
            {
                noconnection();
            }
        }
        else if (request.isHttpError)
        {
            if (request.responseCode == 400)
            {
                Debug.Log("Http error: Message data missing: " + request.error + ", Code = " + request.responseCode + " " + request.downloadHandler.text);
            }
            else if (request.responseCode == 404)
            {
                Debug.Log("Http error: Recipient or parent not found: " + request.error + ", Code = " + request.responseCode + " " + request.downloadHandler.text);
            }
            else if (request.responseCode == 500)
            {
                Debug.Log("Http error: Database search failed: " + request.error + ", Code = " + request.responseCode);
            }

            if (failure != null)
            {
                failure();
            }
        }
        else if (request.responseCode == 200)
        {
            // response contains the message
            //Debug.Log("Message sent: " + request.downloadHandler.text);
            GetMessages(true, () => { success(); }, noconnection, () => { failure(); });
        }
    }
コード例 #8
0
 /// <summary>
 /// Creates an empty NetworkEntity
 /// </summary>
 protected NetworkEntity()
     : base()
 {
     this.messageSentCallback = null;
 }
コード例 #9
0
 /// <summary>
 /// Constructs a new NetworkEntity
 /// </summary>
 /// <param name="entityOwner">Reference (ref) to the socket who will be the owner of this object.</param>
 public NetworkEntity(ref Socket entityOwner)
     : base(ref entityOwner)
 {
     this.messageSentCallback = null;
 }
コード例 #10
0
 /// <summary>
 /// Set the method to the underlaying callback reference.
 /// </summary>
 /// <param name="method">Method to be called.</param>
 public void SetMessageSentCallback(MessageSentCallback method)
 {
     this.messageSentCallback += method;
 }
コード例 #11
0
ファイル: Interop.Messages.cs プロジェクト: yunmiha/TizenFX
 internal static extern int SendMessage(IntPtr serviceHandle, IntPtr messageHandle, bool saveToSentbox, MessageSentCallback cb, IntPtr userData);