locked
How to establish connection Server->Client? RRS feed

  • Question

  • User-80771130 posted

    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

    Thursday, May 11, 2017 11:13 AM

All replies

  • User-271186128 posted

    Hi win32nipuh,

    win32nipuh

    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 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

    Friday, May 12, 2017 7:32 AM
  • User-80771130 posted

    Thank you.

    Ok, I understand that probably it is off-topic but how do you think: is it possible to do using WebSockets? 

    Friday, May 12, 2017 10:06 AM
  • User-271186128 posted

    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

    Monday, May 15, 2017 2:44 AM
  • User-80771130 posted

    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? 

    Monday, May 15, 2017 9:02 AM
  • User-271186128 posted

    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.

      //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);
            }
        }
    

    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

    Monday, May 22, 2017 8:47 AM
  • User753101303 posted

    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).

    Monday, May 22, 2017 5:50 PM
  • User-80771130 posted

    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

    Saturday, May 27, 2017 6:34 AM