当前位置: 首页>>代码示例>>C#>>正文


C# Connection.Send方法代码示例

本文整理汇总了C#中Connection.Send方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.Send方法的具体用法?C# Connection.Send怎么用?C# Connection.Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connection的用法示例。


在下文中一共展示了Connection.Send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            var messageListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, new List<string>());
            var messageList = FindViewById<ListView>(Resource.Id.Messages);
            messageList.Adapter = messageListAdapter;

            var connection = new Connection("http://10.0.2.2:8081/echo");
            connection.Received += data =>
                RunOnUiThread(() => messageListAdapter.Add(data));

            var sendMessage = FindViewById<Button>(Resource.Id.SendMessage);
            var message = FindViewById<TextView>(Resource.Id.Message);

            sendMessage.Click += delegate
            {
                if (!string.IsNullOrWhiteSpace(message.Text) && connection.State == ConnectionState.Connected)
                {
                    connection.Send("Android: " + message.Text);

                    RunOnUiThread(() => message.Text = "");
                }
            };

            connection.Start().ContinueWith(task => connection.Send("Android: connected"));
        }
开发者ID:cryophobia,项目名称:SignalR,代码行数:29,代码来源:DemoActivity.cs

示例2: RunRawConnection

        private async Task RunRawConnection()
        {
            string url = "http://signalr01.cloudapp.net/raw-connection";

            var connection = new Connection(url);
            connection.TraceWriter = _traceWriter;

            await connection.Start();
            connection.TraceWriter.WriteLine("transport.Name={0}", connection.Transport.Name);

            await connection.Send(new { type = 1, value = "first message" });
            await connection.Send(new { type = 1, value = "second message" });
        }
开发者ID:selzero,项目名称:SignalR-Clients,代码行数:13,代码来源:CommonClient.cs

示例3: RunInMemoryHost

        private static void RunInMemoryHost()
        {
            var host = new MemoryHost();
            host.MapConnection<MyConnection>("/echo");

            var connection = new Connection("http://foo/echo");

            connection.Received += data =>
            {
                Console.WriteLine(data);
            };

            connection.Start(host).Wait();

            ThreadPool.QueueUserWorkItem(_ =>
            {
                try
                {
                    while (true)
                    {
                        connection.Send(DateTime.Now.ToString());

                        Thread.Sleep(2000);
                    }
                }
                catch
                {

                }
            });
        }
开发者ID:ninjaAB,项目名称:SignalR,代码行数:31,代码来源:Program.cs

示例4: SendingCommandObjectSetsCommandOnBus

        public void SendingCommandObjectSetsCommandOnBus()
        {
            var messageBus = new Mock<IMessageBus>();
            var counters = new Mock<IPerformanceCounterWriter>();
            Message message = null;
            messageBus.Setup(m => m.Publish(It.IsAny<Message>())).Returns<Message>(m =>
            {
                message = m;
                return TaskAsyncHelper.Empty;
            });

            var serializer = new JsonNetSerializer();
            var traceManager = new Mock<ITraceManager>();
            var connection = new Connection(messageBus.Object,
                                            serializer,
                                            "signal",
                                            "connectonid",
                                            new[] { "a", "signal", "connectionid" },
                                            new string[] { },
                                            traceManager.Object,
                                            counters.Object);

            connection.Send("a", new Command
            {
                Type = CommandType.AddToGroup,
                Value = "foo"
            });

            Assert.NotNull(message);
            Assert.True(message.IsCommand);
            var command = serializer.Parse<Command>(message.Value);
            Assert.Equal(CommandType.AddToGroup, command.Type);
            Assert.Equal("foo", command.Value);
        }
开发者ID:arjunshetty2020,项目名称:SignalR,代码行数:34,代码来源:ConnectionFacts.cs

示例5: Handle

        public override void Handle(Connection connection)
        {
            var account = connection.Session.Account;
            var notification = new Notification();

            notification.UserId = account.Id;
            notification.Regex = new Regex(RegexPattern);
            notification.DeviceToken = DeviceToken;

            if (Program.NotificationManager.Exists(DeviceToken))
            {
                notification.Save();
            }
            else
            {
                if (Program.NotificationManager.FindWithId(account.Id).Count() < 5)
                {
                    notification.Insert();
                }
                else
                {
                    connection.SendSysMessage("You may only have 5 devices registered for push notifications.");
                    return;
                }
            }

            Program.NotificationsDirty = true;

            var notificationSubscription = new NotificationSubscription();
            notificationSubscription.DeviceToken = DeviceToken;
            notificationSubscription.RegexPattern = RegexPattern;
            notificationSubscription.Registered = true;

            connection.Send(notificationSubscription);
        }
开发者ID:Rohansi,项目名称:RohBot,代码行数:35,代码来源:NotificationSubscriptionRequest.cs

示例6: SendingCommandObjectSetsCommandOnBus

        public void SendingCommandObjectSetsCommandOnBus()
        {
            var messageBus = new Mock<INewMessageBus>();
            Message message = null;
            messageBus.Setup(m => m.Publish(It.IsAny<Message>())).Callback<Message>(m => message = m);
            var serializer = new JsonNetSerializer();
            var traceManager = new Mock<ITraceManager>();
            var connection = new Connection(messageBus.Object,
                                            serializer,
                                            "signal",
                                            "connectonid",
                                            new[] { "a", "signal", "connectionid" },
                                            new string[] { },
                                            traceManager.Object);

            connection.Send("a", new Command
            {
                Type = CommandType.AddToGroup,
                Value = "foo"
            });

            Assert.NotNull(message);
            Assert.True(message.IsCommand);
            var command = serializer.Parse<Command>(message.Value);
            Assert.Equal(CommandType.AddToGroup, command.Type);
            Assert.Equal(@"{""Name"":""foo"",""Cursor"":null}", command.Value);
        }
开发者ID:Shira-Z,项目名称:SignalR-1,代码行数:27,代码来源:ConnectionFacts.cs

示例7: Handle

        public override void Handle(Connection connection)
        {
            var account = connection.Session.Account;
            var notification = Program.NotificationManager.Get(DeviceToken);

            if (notification == null)
            {
                connection.SendSysMessage("This device is not registered for push notifications.");
                return;
            }

            if (notification.UserId != account.Id)
            {
                connection.SendSysMessage("This device is not registered with your account.");
                return;
            }

            notification.Remove();

            Program.NotificationsDirty = true;

            var notificationSubscription = new NotificationSubscription();
            notificationSubscription.DeviceToken = DeviceToken;
            notificationSubscription.RegexPattern = RegexPattern;
            notificationSubscription.Registered = false;

            connection.Send(notificationSubscription);
        }
开发者ID:Rohansi,项目名称:RohBot,代码行数:28,代码来源:NotificationUnsubscriptionRequest.cs

示例8: Main

 static void Main(string[] args)
 {
     myList<byte> msgs;
     string strmsg;
     Connection cc = new Connection();
     cc.Connect();
     Connection sc = new Connection("chat.facebook.com");
     sc.Connect();
     while (true)
     {
         strmsg = "";
         msgs = cc.GetMessages();
         if ((msgs != null) && (msgs.Count > 0))
         {
             strmsg = ConvertMsgToString(msgs);
             sc.Send(msgs);
         }
         msgs = sc.GetMessages();
         if ((msgs != null) && (msgs.Count > 0))
         {
             strmsg = ConvertMsgToString(msgs);
             cc.Send(msgs);
         }
         if (strmsg.Length > 0)
         {
             Console.WriteLine(strmsg);
         }
         if (strmsg.Contains("proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\""))
         {
             cc.StartTls();
             sc.StartTls();
         }
     }
 }
开发者ID:leader80,项目名称:xmpproxy,代码行数:34,代码来源:Program.cs

示例9: FinishedLaunching

        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow (UIScreen.MainScreen.Bounds);

            var message = new EntryElement("Message", "Type your message here", "");
            var sendMessage = new StyledStringElement("Send Message")
            {
                Alignment = UITextAlignment.Center,
                BackgroundColor = UIColor.Green
            };
            var receivedMessages = new Section();
            var root = new RootElement("")
            {
                new Section() { message, sendMessage },
                receivedMessages
            };

            var connection = new Connection("http://localhost:8081/echo");

            sendMessage.Tapped += delegate
            {
                if (!string.IsNullOrWhiteSpace(message.Value) && connection.State == ConnectionState.Connected)
                {
                    connection.Send("iOS: " + message.Value);

                    message.Value = "";
                    message.ResignFirstResponder(true);
                }
            };

            connection.Received += data =>
            {
                InvokeOnMainThread(() =>
                    receivedMessages.Add(new StringElement(data)));
            };

            connection.Start().ContinueWith(task =>
                connection.Send("iOS: Connected"));

            var viewController = new DialogViewController(root);
            window.RootViewController = viewController;

            window.MakeKeyAndVisible ();

            return true;
        }
开发者ID:cryophobia,项目名称:SignalR,代码行数:46,代码来源:AppDelegate.cs

示例10: Example

    void Example()
    {
        Connection conn = new Connection("COM1");

        conn.ReceivedMessage += Conn_ReceivedMessage;

        Message msg = new Message(conn, Commands.DATEGET, Flags.NONE, 0);

        conn.Send(msg);
    }
开发者ID:DragDay7,项目名称:posnet-csharp,代码行数:10,代码来源:Example.cs

示例11: Handle

        public override void Handle(Connection connection)
        {
            if (Program.DelayManager.AddAndCheck(connection, DelayManager.Database))
                return;

            if (connection.Session == null)
            {
                connection.SendSysMessage("You need to be logged in to do that.");
                return;
            }

            if (!connection.Session.IsInRoom(Target))
            {
                connection.SendSysMessage("You are not in that room.");
                return;
            }

            var room = Program.RoomManager.Get(Target);
            if (room == null)
            {
                connection.SendSysMessage("Room does not exist.");
                return;
            }

            if (room.IsPrivate && room.IsBanned(connection.Session.Account.Name))
                return;

            List<HistoryLine> lines;
            if (Util.DateTimeFromTimestamp(AfterDate) < (DateTime.UtcNow - Util.MaximumHistoryRequest))
            {
                lines = new List<HistoryLine>();
            }
            else
            {
                var cmd = new SqlCommand("SELECT * FROM rohbot.chathistory WHERE chat=lower(:chat) AND date<:afterdate ORDER BY date DESC LIMIT 100;");
                cmd["chat"] = Target;
                cmd["afterdate"] = AfterDate;

                lines = cmd.Execute().Select(r => (HistoryLine)HistoryLine.Read(r)).ToList();
                lines.Reverse();
            }

            if (lines.Count == 0)
                lines.Add(new ChatLine(0, Target, "Steam", Program.Settings.PersonaName, "0", "", "No additional history is available.", false));

            var history = new ChatHistory
            {
                ShortName = room.RoomInfo.ShortName,
                Requested = true,
                Lines = lines
            };

            connection.Send(history);
        }
开发者ID:Naarkie,项目名称:RohBot,代码行数:54,代码来源:ChatHistoryRequest.cs

示例12: OnSendHistory

    public bool OnSendHistory(Connection connection)
    {
        var lines = new List<HistoryLine>();

        lines.Add(Message(_greetings[new Random().Next(_greetings.Count)]));

        if (connection.Session == null)
        {
            lines.Add(Message("this is a web interface for steam group chats (try it on your phone!)"));
            lines.Add(Message("you will need to create an account to use it"));
        }
        else
        {
            lines.Add(Message("to join a room click on its name below"));
            lines.Add(Message(""));

            var rooms = Program.RoomManager.List.Where(r => !r.IsHidden);
            foreach (var room in rooms)
            {
                var shortName = room.RoomInfo.ShortName;
                var name = room.RoomInfo.Name;
                var notes = new List<string>();

                name = JsLink("join('" + shortName +"')", name);

                if (room is SteamRoom)
                    notes.Add(Link("http://steamcommunity.com/gid/" + room.RoomInfo["SteamId"], "steam"));

                if (room.IsWhitelisted)
                    notes.Add("whitelisted");

                if (room.IsPrivate)
                    notes.Add("private");

                lines.Add(Message(string.Format("{0}{1}{2}",
                    name,
                    notes.Count == 0 ? "" : " -- ",
                    string.Join(", ", notes))));
            }
        }

        lines.Add(Message(""));
        lines.Add(Message("need help with commands? " + Link("https://github.com/Rohansi/SteamMobile#commands", "read this")));
        lines.Add(Message("want me in your group? " + Link("http://steamcommunity.com/id/rohans/", "talk to this guy")));

        connection.Send(new ChatHistory
        {
            ShortName = "home",
            Requested = false,
            Lines = lines
        });

        return false;
    }
开发者ID:krixalis,项目名称:RohBot,代码行数:54,代码来源:Home.cs

示例13: Main

        static void Main(string[] args)
        {
            var connection = new Connection("http://localhost:2329/Home/echo");
            connection.Received += data =>
                {
                    Console.WriteLine(data);
                };

            connection.Start().Wait();
            connection.Send("Testing from C# Console App");

            Console.ReadLine();
        }
开发者ID:denmerc,项目名称:SignalR.Demo,代码行数:13,代码来源:Program.cs

示例14: Connect

 public bool Connect(string worldId, string roomType, string code = "")
 {
     if (loggedIn)
     {
         PlayerIOError error = null;
         client.Multiplayer.CreateJoinRoom(
             worldId,
             roomType,
             true,
             null,
             null,
             delegate(Connection tempConnection)
             {
                 connection = tempConnection;
                 connection.OnDisconnect += this.OnDisconnect;
                 connection.OnMessage += this.OnMessage;
                 connection.Send("init");
                 connection.Send("init2");
             },
             delegate(PlayerIOError tempError)
             {
                 error = tempError;
             });
         while (!connected && error == null) { }
         if (connection.Connected)
         {
             //connection.Send("access", form..Text);
             return true;
         }
         else
         {
             MessageBox.Show("Could not connect: " + error);
             return false;
         }
     }
     else
         return false;
 }
开发者ID:CheeseSoftware,项目名称:DynamicEEBot,代码行数:38,代码来源:BotBase.cs

示例15: signalr_connection_is_alive

        public void signalr_connection_is_alive()
        {
            this._autoResetEvent = new AutoResetEvent(false);

            var connection = new Connection("http://localhost:2329/echo");
            connection.Received += data =>
            {
                this._autoResetEvent.Set();
                Console.WriteLine(data);
                Assert.Pass();
            };

            connection.Start().Wait();
            connection.Send("Testing from C# Console App");
            this._autoResetEvent.WaitOne();
        }
开发者ID:denmerc,项目名称:SignalR.Demo,代码行数:16,代码来源:ConnectionTests.cs


注:本文中的Connection.Send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。