本文整理汇总了C#中Microsoft.AspNet.SignalR.Client.HubConnection.Start方法的典型用法代码示例。如果您正苦于以下问题:C# HubConnection.Start方法的具体用法?C# HubConnection.Start怎么用?C# HubConnection.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.SignalR.Client.HubConnection
的用法示例。
在下文中一共展示了HubConnection.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectToSignalR
private async Task ConnectToSignalR()
{
hubConnection = new HubConnection(App.MobileService.ApplicationUri.AbsoluteUri);
if (user != null)
{
hubConnection.Headers["x-zumo-auth"] = user.MobileServiceAuthenticationToken;
}
else
{
hubConnection.Headers["x-zumo-application"] = App.MobileService.ApplicationKey;
}
proxy = hubConnection.CreateHubProxy("ChatHub");
await hubConnection.Start();
proxy.On<string>("helloMessage", async (msg) =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
message += " " + msg;
Message.Text = message;
});
});
}
示例2: SendToGroupFromOutsideOfHub
public async Task SendToGroupFromOutsideOfHub()
{
using (var host = new MemoryHost())
{
IHubContext<IBasicClient> hubContext = null;
host.Configure(app =>
{
var configuration = new HubConfiguration
{
Resolver = new DefaultDependencyResolver()
};
app.MapSignalR(configuration);
hubContext = configuration.Resolver.Resolve<IConnectionManager>().GetHubContext<SendToSome, IBasicClient>();
});
var connection1 = new HubConnection("http://foo/");
using (connection1)
{
var wh1 = new AsyncManualResetEvent(initialState: false);
var hub1 = connection1.CreateHubProxy("SendToSome");
await connection1.Start(host);
hub1.On("send", wh1.Set);
hubContext.Groups.Add(connection1.ConnectionId, "Foo").Wait();
hubContext.Clients.Group("Foo").send();
Assert.True(await wh1.WaitAsync(TimeSpan.FromSeconds(10)));
}
}
}
示例3: Main
static void Main(string[] args)
{
Console.Write("Enter your Name: ");
name = Console.ReadLine();
HubConnection connection = new HubConnection("http://localhost:51734");
proxy = connection.CreateHubProxy("ChatHub");
connection.Received += Connection_Received;
Action<string, string> SendMessageRecieved = recieved_a_message;
proxy.On("broadcastMessage", SendMessageRecieved);
Console.WriteLine("Waiting for connection");
connection.Start().Wait();
Console.WriteLine("You can send messages now.");
connection.StateChanged += Connection_StateChanged;
string input;
while ((input = Console.ReadLine()) != null)
{
proxy.Invoke("Send", new object[] { name, input });
}
}
示例4: Run
public void Run()
{
System.Console.WriteLine("Starting connection to host at: {0} with launcher identifier name as {1}", AppSettings.HostUrl, AppSettings.LauncherName);
var hubConnection = new HubConnection(AppSettings.HostUrl);
IHubProxy hubProxy = hubConnection.CreateHubProxy("LauncherHub");
hubProxy.On<LauncherCommand>("sendCommand", OnSendCommand);
hubProxy.On<IEnumerable<LauncherSequence>>("sendSequence", OnSendSequence);
ServicePointManager.DefaultConnectionLimit = 10;
hubConnection.Start().Wait();
hubConnection.StateChanged += change =>
{
System.Console.WriteLine("Connection to host state has changed to : " + change.NewState);
if (change.NewState == ConnectionState.Connected)
{
hubProxy.Invoke("Initialize", AppSettings.LauncherName);
}
};
hubProxy.Invoke("Initialize", AppSettings.LauncherName);
System.Console.WriteLine("Connection established.... waiting for commands from host...");
while (true)
{
// let the app know we are health every 1000 (Ms = 1 second) * 60 sec = 1 min *
Thread.Sleep(1000 * 60 * 5);
hubProxy.Invoke("Initialize", AppSettings.LauncherName);
}
}
示例5: RunHubConnectionAPI
private async Task RunHubConnectionAPI(string url)
{
var hubConnection = new HubConnection(url);
hubConnection.TraceWriter = _traceWriter;
var hubProxy = hubConnection.CreateHubProxy("HubConnectionAPI");
hubProxy.On<string>("displayMessage", (data) => hubConnection.TraceWriter.WriteLine(data));
await hubConnection.Start();
hubConnection.TraceWriter.WriteLine("transport.Name={0}", hubConnection.Transport.Name);
await hubProxy.Invoke("DisplayMessageCaller", "Hello Caller!");
string joinGroupResponse = await hubProxy.Invoke<string>("JoinGroup", hubConnection.ConnectionId, "CommonClientGroup");
hubConnection.TraceWriter.WriteLine("joinGroupResponse={0}", joinGroupResponse);
await hubProxy.Invoke("DisplayMessageGroup", "CommonClientGroup", "Hello Group Members!");
string leaveGroupResponse = await hubProxy.Invoke<string>("LeaveGroup", hubConnection.ConnectionId, "CommonClientGroup");
hubConnection.TraceWriter.WriteLine("leaveGroupResponse={0}", leaveGroupResponse);
await hubProxy.Invoke("DisplayMessageGroup", "CommonClientGroup", "Hello Group Members! (caller should not see this message)");
await hubProxy.Invoke("DisplayMessageCaller", "Hello Caller again!");
}
示例6: OpenConnection
public void OpenConnection()
{
_connection = new HubConnection(_hubUrl);
_alertHubProxy = _connection.CreateHubProxy("alertHub");
_resourceHubProxy = _connection.CreateHubProxy("resourceHub");
_connection.Start().Wait();
}
示例7: Connect
private async void Connect()
{
Connection = new HubConnection(ServerURI);
HubProxy = Connection.CreateHubProxy("NotifierHub");
HubProxy.On<AlarmMessage>("SendNotification", async (notification) =>
{
await this.AlarmsList.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
this.AlarmsList.Items.Add(notification);
});
}
);
try
{
await Connection.Start();
}
catch (HttpRequestException)
{
return;
}
catch (Exception)
{
return;
}
}
示例8: StartConnection
private async void StartConnection()
{
// Connect to the server
try
{
var hubConnection = new HubConnection("http://192.168.0.43:61893/");
// Create a proxy to the 'ChatHub' SignalR Hub
chatHubProxy = hubConnection.CreateHubProxy("ChatHub");
// Wire up a handler for the 'UpdateChatMessage' for the server
// to be called on our client
chatHubProxy.On<string,string>("broadcastMessage", (name, message) => {
var str = $"{name}:{message}\n";
RunOnUiThread(()=> text.Append( str ) );
});
// Start the connection
await hubConnection.Start();
}
catch (Exception e)
{
text.Text = e.Message;
}
}
示例9: GetProxy
public async static Task<IHubProxy> GetProxy(String hubName)
{
var hubConnection = new HubConnection(ConfigurationManager.AppSettings.Get("ServerAddressAndPort"));
IHubProxy proxy = null;
switch (hubName)
{
case "UserHub":
{
proxy = hubConnection.CreateHubProxy("UserHub");
break;
}
case "MessageHub":
{
proxy = hubConnection.CreateHubProxy("MessageHub");
break;
}
case "ConversationHub":
{
proxy = hubConnection.CreateHubProxy("ConversationHub");
break;
}
}
ServicePointManager.DefaultConnectionLimit = 20;
await hubConnection.Start();
return proxy;
}
示例10: btnCon_Click
private async Task btnCon_Click(object sender, EventArgs e)
{
this.btnInvok.Enabled = false;
hubConnection = new HubConnection(txtUrl.Text);
stockTickerHubProxy = hubConnection.CreateHubProxy("TickerHub");
strongHubProxy = hubConnection.CreateHubProxy("StrongHub");
this.btnCon.Enabled = false;
try
{
await hubConnection.Start(new WebSocketTransport());
this.btnInvok.Enabled = true;
}
catch (Exception ex)
{
Exception temp = ex;
string msg = temp.Message;
while (temp.InnerException != null)
{
temp = temp.InnerException;
msg += "\r\n" + temp.Message;
}
MessageBox.Show(msg);
}
this.btnCon.Enabled = true;
}
示例11: SignalRProxySingleton
public SignalRProxySingleton()
{
conn = new HubConnection(ConfigurationManager.AppSettings["SignalRURL"]);
homeHub = conn.CreateHubProxy(ConfigurationManager.AppSettings["HubName"]);
conn.Start().GetAwaiter().GetResult();
}
示例12: CustomerUpdateNotifier
internal CustomerUpdateNotifier()
{
var hubConnection = new HubConnection(AppSettings.CustomerUpdateHubUrl);
_hubProxy = hubConnection.CreateHubProxy(AppSettings.CustomerUpdateHubName);
hubConnection.Start().Wait();
}
示例13: Main
static void Main()
{
Console.WriteLine("Creating hub");
using (var hubConnection = new HubConnection("http://localhost:1906/"))
{
var eventHubProxy = hubConnection.CreateHubProxy("EventHub");
eventHubProxy.On<Message>("Receive", message => OnReceive(message));
//eventHubProxy.On<Message>("UpdateConfiguration", message => OnUpdateConfiguration(message));
hubConnection.Start().Wait();
//eventHubProxy.Invoke<Message>("RequestConfiguration").Wait();
Console.WriteLine("Hub created");
while (true)
{
Console.Write("Values: ");
var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(Console.ReadLine());
var message = new Message
{
Sender = typeof(Program).FullName,
Target = "ArtNet",
Time = DateTime.Now,
Values = values
};
Console.WriteLine("Sending message");
eventHubProxy.Invoke<Message>("Send", message).Wait();
Console.WriteLine("Message sent");
}
}
}
示例14: ConnectAsync
private async void ConnectAsync()
{
con = new HubConnection(ServerURI);
con.Closed += Connection_Closed;
con.Error += Connection_Error;
HubProxy = con.CreateHubProxy("MyHub");
//Handle incoming event from server: use Invoke to write to console from SignalR's thread
HubProxy.On<string>("getPos", (message) =>
Dispatcher.BeginInvoke(() => test(message))
);
try
{
await con.Start();
}
catch (HttpRequestException)
{
//No connection: Don't enable Send button or show chat UI
btntrack.Content = "eror";
}
catch (HttpClientException)
{
btntrack.Content = "eror";
}
Dispatcher.BeginInvoke(() =>
{
HubProxy.Invoke("Connect", "15");
});
}
示例15: CrestLogger
public CrestLogger()
{
var hubConnection = new HubConnection("http://www.contoso.com/");
errorLogHubProxy = hubConnection.CreateHubProxy("ErrorLogHub");
//errorLogHubProxy.On<Error>("LogError", error => { });
hubConnection.Start().Wait();
}