Reputation: 148
I needed your help please. It turns out that by signalR, I'm trying to get information from the client's computer from the server, in this case, I want to get the name of the client's computer.
But it turns out that when there is more than one computer, I get the same name from the computer on the client computers, that is, if I connect first, I get the name of the computer correctly, but if I go to another computer, I get the name of the first PC computer that was connected, instead of showing the real one.
The code I have is from a web application (Server) that connects to the windform application. I show you the code:
$(document).ready(function () {
var myHub = $.connection.myHub;
myHub.client.getNamePC = function (pcName) {
$('#NamePC').val(pcName);
}
$.connection.hub.url = "http://localhost:50684/signalr";
$.connection.hub.start().done(function () {
$('#btnSubmit').click(function (e) {
myHub.server.broadcastMessageToNamePC("Esperando Solicitud Nombre Equipo");
});
}).fail(function (error) {
console.error(error);
});
});
<div>
<input type="text" id="NamePC" />
<input type="submit" id="btnSubmit" value="Get Name PC" />
</div>
In the HUB file:
public void BroadcastMessageToNamePC(string pcName)
{
Clients.All.getNamePC(pcName);
}
In the windform client application:
public partial class Form1 : Form
{
HubConnection hubConnection;
IHubProxy hubProxy;
public Form1()
{
InitializeComponent();
IncializaSignalR();
hubConnection.Closed += IncializaSignalR;
hubConnection.Start().Wait();
}
private void IncializaSignalR()
{
try
{
String dirServer= "https://ejemplo.cl"
hubConnection = new HubConnection(dirServer + "/signalr/hubs");
hubProxy = hubConnection.CreateHubProxy("MyHub");
CheckForIllegalCrossThreadCalls = false;
hubProxy.On<String>("getNamePC ", (pcName) =>
{
namePc();
hubConnection.Stop();
hubConnection.Closed += IncializaSignalR;
hubConnection.Start().Wait();
}
private string namePc()
{
string NamePC_client= System.Environment.MachineName;
if (hubProxy != null)
{
hubProxy.Invoke("BroadcastMessageToNamePC", pcName);
}
return NamePC_client;
}
The goal is, when I open my web page that is published on production site, I can get the name of my computer, which is the client in which this work, if anyone knows, your help is appreciated.
Best regards.
Upvotes: 0
Views: 1222
Reputation: 13146
I want to get the name of the client's computer
It is not possible in usual way. Maybe you can retrieve it by using ActiveX and some kind of plugins but generally you can't grab this information. You can get information about browser or IP addresses by using Javascript but you can't get computer name. It would be a security issue.
Upvotes: 1