Skip to content

Instantly share code, notes, and snippets.

@polatengin
Created October 16, 2016 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polatengin/1ec1f103e04cce2ef6bb865f3a90d30c to your computer and use it in GitHub Desktop.
Save polatengin/1ec1f103e04cce2ef6bb865f3a90d30c to your computer and use it in GitHub Desktop.
Asp.Net Core üzerinde SignalR kullanımı
using Microsoft.AspNetCore.SignalR;
namespace ConsoleApplication
{
public class ChatHub : Hub
{
public void Send(string message)
{
Clients.All.display(message);
}
}
}
<!doctype html>
<html>
<body>
<textarea id="chatArea" cols="50" rows="20"></textarea>
<br /><br />
<input id="message" type="text" />
<input id="send" type="button" value="Gonder" />
<script src="http://code.jquery.com/jquery-2.2.4.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/signalr/jquery.signalr-2.0.3.js"></script>
<script src="/signalr/js"></script>
<script>
var hub = $.connection.chatHub;
hub.client.display = function(received) {
chatArea.value += received + \n;
};
send.addEventListener(‘click’, function() {
hub.server.send(message.value);
});
$.connection.hub.start();
</script>
</body>
</html>
<?xml version="1.0" encoding="utf-8">
<configuration>
<packageSources>
<clear />
<add key="aspnetcidev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory() + "/wwwroot")
.UseStartup<Startup>()
.Build();
host.Run();
}
using System.IO;
using Microsoft.AspNetCore.Hosting;
dependencies": {
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0-*",
"Microsoft.AspNetCore.StaticFiles": "1.1.0-*",
"Microsoft.AspNetCore.SignalR.Server": "0.2.0-*",
"Microsoft.AspNetCore.WebSockets": "0.2.0-*"
}
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
namespace ConsoleApplication
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSignalR();
}
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory() + "/wwwroot")),
RequestPath = new PathString("")
});
app.UseWebSockets();
app.UseSignalR();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment