How to establish connection Server->Client (not Client->Server) and after this work as usually : Client sends->Request->Server and receives Responses from the Server
How to establish connection Server->Client (not Client->Server)
From my point of view, it is impossible in SignalR to establish connection to client by server. Because before the establishment of the connection, the server doesn't know the endpoint of the client, and simply doesn't know which endpoint to establish the
connection.
If you have any other questions, please feel free to contact me any time.
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
If you are using websocket directly, and already know the endpoint of the client, that's of course available.
But the issue is how to let the server know the endpoint of the client before connecting?
So if you want to connect the client by the server, the server must know the endpoint of the client before establishing connection.
The following link might help you understand this issue. https://www.websocket.org/aboutwebsocket.html
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Client applications know the cloud address only, they connect to A and send requests
Service at B connects to the client at A, and then A passes all clients requests to A, A process the requests and sends responses back to B, and B replies to clients.
That is why I am trying to solve somehow the task: B connects to A and then A sends requests to B etc.
I think I can use SignalR like this:
B connects to some group at A, then A sends messages to this group or to the SignalR "user" at B.
(1) B has been connected to A.
C has been connected to A.
D has been connected to A.
(2) Now you want to notify Computer C and D by Computer B, so you want to get all clients from A, and then notify other clients by B.
But we can change another way to solve this problem.
The Computer A is already know all clients, when you want to notify other clients by B , first B can send the notify to A, and then notify all the clients except B by A.
The following code might help you.
the part of the code on client.
//notify the server to send message to other clients
exampleHub.server.notifyServer("I want to notify other clients ");
the part of the code on server.
[HubName("ExampleHub")]
public class ExampleHub : Hub
{
/// <summary>
/// send message to other clients except self on server
/// </summary>
public void NotifyServer(string message)
{
Clients.AllExcept(Context.ConnectionId).sendMessageToOtherClients(message);
}
}
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
It it still a technical description of some problem you want to solve. Knowing the actual underlying goal may help to better understand what you actually want to do and then how to "best" do that. At some point you got the letter wrong and it's seems requests
and responses are mixed ie you are telling "A process the requests and sends responses back to B" and "then A sends requests to B" which doesn't seems to be the same thing ? Also I have no idea if you are talking about "custom" Ajax requests or browser http
requests etc...
Basically it looks like you have a server (A). But if a B service connects itself to A, you still want A to process the request but the response is sent to B which respond to the client? Also it really depends the kind of "response" you are talking about.
It seems it would be really complex to get this to work. I see :
- client would send a request to A with would respond by asking to the client to start as well a conversation with B
- then when the client talks to A, A would send a message to B and B could then send the message to the client (edit: but which benefit does it bring ?).
Else it "almost" looks like a proxy ie the request might go to B which sends the request to A for processing and then the response comes from A to B which forward this to the client.
Else if it is really " B connects to A and then A sends requests to B" then I don't see the problem (if B connects to , A knows how to respond to B).
If you need further help I would suggest to describe your goal (for know it seems rather the description of a technical solution but I have no idea about which real world problem it tries to solve).
I'd like to implement something like reverse tunnel.
In other words, imagine:
I install my WCF service to my local machine (A), provide my client app to users (C,D,E) and give them the ip /url of machine B (cloud).
This way users know always the one fixed url and do not know where is real WCF Service works.
They connect to B and think the WCF service works on B, but really it works on A, and later I can switch it to my another local machine A2 or A3 etc.
But user works with the same url and do not know where is the real service.
For this goal I want to create small client/server pair for connection establishing and passing requests/responses and install thme on B and A.
It is no avoid the open additional ports on A (for B->A connection, i.e from cloud to my local machine) I'd like to initiate connection A->B via http:80 for example, and then
B passes all requests from C,D,E to A, receives the responses and passes them back.
Here are requests/responses - the low-level soap or restful requests/responses
I'd like to add this new functionality to this implementation
https://github.com/sailro/Bdtunnel
The BDTunnel works fine but the connection established by client to server, usual way.
If server can connect to the client in BDTunnel it will be what I need, it will be the reverse tunnel
None
0 Points
4 Posts
How to establish connection Server->Client?
May 11, 2017 11:14 AM|win32nipuh|LINK
How to establish connection Server->Client (not Client->Server) and after this work as usually : Client sends->Request->Server and receives Responses from the Server
All-Star
45489 Points
7008 Posts
Microsoft
Re: How to establish connection Server->Client?
May 12, 2017 07:32 AM|Zhi Lv - MSFT|LINK
Hi win32nipuh,
From my point of view, it is impossible in SignalR to establish connection to client by server. Because before the establishment of the connection, the server doesn't know the endpoint of the client, and simply doesn't know which endpoint to establish the connection.
If you are want to know how to use SignalR, the tutorial in the following links might help you.
https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr
https://github.com/SignalR/Samples
If you have any other questions, please feel free to contact me any time.
Best regards,
Dillion
None
0 Points
4 Posts
Re: How to establish connection Server->Client?
May 12, 2017 10:06 AM|win32nipuh|LINK
Thank you.
Ok, I understand that probably it is off-topic but how do you think: is it possible to do using WebSockets?
All-Star
45489 Points
7008 Posts
Microsoft
Re: How to establish connection Server->Client?
May 15, 2017 02:44 AM|Zhi Lv - MSFT|LINK
Hi win32nipuh,
If you are using websocket directly, and already know the endpoint of the client, that's of course available.
But the issue is how to let the server know the endpoint of the client before connecting?
So if you want to connect the client by the server, the server must know the endpoint of the client before establishing connection.
The following link might help you understand this issue.
https://www.websocket.org/aboutwebsocket.html
Best regards,
Dillion
None
0 Points
4 Posts
Re: How to establish connection Server->Client?
May 15, 2017 09:02 AM|win32nipuh|LINK
Hi Dillion,
thank you.
My idea is:
A is in cloud, I run my service there.
B is on my local machine, I run my client there.
Client applications know the cloud address only, they connect to A and send requests
Service at B connects to the client at A, and then A passes all clients requests to A, A process the requests and sends responses back to B, and B replies to clients.
That is why I am trying to solve somehow the task: B connects to A and then A sends requests to B etc.
I think I can use SignalR like this:
B connects to some group at A, then A sends messages to this group or to the SignalR "user" at B.
But how B can respond to A in this case?
All-Star
45489 Points
7008 Posts
Microsoft
Re: How to establish connection Server->Client?
May 22, 2017 08:47 AM|Zhi Lv - MSFT|LINK
Hi win32nipuh,
Accord to your description , I can be sure to tell you that this can be implemented in signlar.
Suppose, there are 4 computers
Computer A(Server)
Computer B(Client)
Computer C(Client)
Computer D(Client)
(1) B has been connected to A.
C has been connected to A.
D has been connected to A.
(2) Now you want to notify Computer C and D by Computer B, so you want to get all clients from A, and then notify other clients by B.
But we can change another way to solve this problem.
The Computer A is already know all clients, when you want to notify other clients by B , first B can send the notify to A, and then notify all the clients except B by A.
The following code might help you.
the part of the code on client.
the part of the code on server.
The following link is a tutorial for how to use signalr.
https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr
Best regards,
Dillion
All-Star
48710 Points
18179 Posts
Re: How to establish connection Server->Client?
May 22, 2017 05:50 PM|PatriceSc|LINK
It it still a technical description of some problem you want to solve. Knowing the actual underlying goal may help to better understand what you actually want to do and then how to "best" do that. At some point you got the letter wrong and it's seems requests and responses are mixed ie you are telling "A process the requests and sends responses back to B" and "then A sends requests to B" which doesn't seems to be the same thing ? Also I have no idea if you are talking about "custom" Ajax requests or browser http requests etc...
Basically it looks like you have a server (A). But if a B service connects itself to A, you still want A to process the request but the response is sent to B which respond to the client? Also it really depends the kind of "response" you are talking about. It seems it would be really complex to get this to work. I see :
- client would send a request to A with would respond by asking to the client to start as well a conversation with B
- then when the client talks to A, A would send a message to B and B could then send the message to the client (edit: but which benefit does it bring ?).
Else it "almost" looks like a proxy ie the request might go to B which sends the request to A for processing and then the response comes from A to B which forward this to the client.
Else if it is really " B connects to A and then A sends requests to B" then I don't see the problem (if B connects to , A knows how to respond to B).
If you need further help I would suggest to describe your goal (for know it seems rather the description of a technical solution but I have no idea about which real world problem it tries to solve).
None
0 Points
4 Posts
Re: How to establish connection Server->Client?
May 27, 2017 06:34 AM|win32nipuh|LINK
Yes, PatriceSc, you are right.
I'd like to implement something like reverse tunnel.
In other words, imagine:
I install my WCF service to my local machine (A), provide my client app to users (C,D,E) and give them the ip /url of machine B (cloud).
This way users know always the one fixed url and do not know where is real WCF Service works.
They connect to B and think the WCF service works on B, but really it works on A, and later I can switch it to my another local machine A2 or A3 etc.
But user works with the same url and do not know where is the real service.
For this goal I want to create small client/server pair for connection establishing and passing requests/responses and install thme on B and A.
It is no avoid the open additional ports on A (for B->A connection, i.e from cloud to my local machine) I'd like to initiate connection A->B via http:80 for example, and then
B passes all requests from C,D,E to A, receives the responses and passes them back.
Here are requests/responses - the low-level soap or restful requests/responses
I'd like to add this new functionality to this implementation
https://github.com/sailro/Bdtunnel
The BDTunnel works fine but the connection established by client to server, usual way.
If server can connect to the client in BDTunnel it will be what I need, it will be the reverse tunnel