Exemple #1
0
        /// <summary>
        /// テキストデータ送信
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public void SendMessage(string data)
        {
            if (dataType == DataType.Byte)
            {
                SendMessage(Encoding.UTF8.GetBytes(data));
            }
            else
            {
#if UNITY_UWP
                if (ws != null && task.IsCompleted == true)
                {
                    task = Task.Run(async() =>
                    {
                        using (var writer = new DataWriter(ws.OutputStream))
                        {
                            writer.WriteString(data);
                            await writer.StoreAsync();
                            writer.DetachStream();
                        }
                    });
                }
#elif UNITY_EDITOR || UNITY_STANDALONE
                if (ws != null)
                {
                    ws.Send(data);
                }
#endif
            }
        }
Exemple #2
0
 void WebSocketSendMessage(object message)
 {
     if (!_webSocket.IsAlive)
     {
         return;
     }
     _webSocket.Send(message.ToString());
     //        Debug.Log("SendMessage\n"+message.ToString());
 }
Exemple #3
0
        public async Task <ResponseMessage> SendMessageAsync(RequestMessage message)
        {
            int?msgId = message.Type == RequestMessage.MessageType.Auth
                ? null
                : new int?(NextId());

            string json = message.BuildRequestJson(msgId);

            sentMessages.Add(message.DetermineMessageId().GetValueOrDefault(), message);

            ws.Send(json);

            return(await message.Task);
        }
Exemple #4
0
    public void sendMessage(string channelID, string message)
    {
        wsPostMessageData msgData = new wsPostMessageData
        {
            id      = Time.time.ToString(), //適当に
            type    = "message",
            channel = channelID,            //"D4WNU3BK7", //@haruka  "C4WNTPLQM", //random
            text    = message
        };

#if WINDOWS_UWP
#else
        ws.Send(JsonUtility.ToJson(msgData));
#endif
    }
Exemple #5
0
 public void Send(byte[] buffer)
 {
     m_Socket.Send(buffer);
 }