本文整理汇总了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"));
}
示例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" });
}
示例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
{
}
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}