public Client(INodeEndpointProtocolClient outerProtocol, ITranslatorProtocolHandlerFactory handlerFactory, TranslatorProtocolFactory factory) : base(factory) { this.clientHandler = handlerFactory.CreateClientHandler(); SetOuterProtocol(outerProtocol); this.Handler = this.clientHandler; this.clientHandler.AttachClient(this); }
public void SetOuterProtocol(INodeEndpointProtocolClient protocol) { if (this.outerProtocol != null) { this.outerProtocol.OnInnerProtocolSet(null); } this.outerProtocol = protocol; this.ParentProtocol = protocol; if (this.outerProtocol != null) { this.outerProtocol.OnInnerProtocolSet(this); } }
public void OnReceivedRequest(INodeEndpointProtocolRequest request) { if (!this.server.Connected) { if (this.client != null) { this.client.Disconnect(); } } else { if (this.client == null) { string message = request.RequestMessage(); if (message.StartsWith("[CONNECTENDPOINT]")) { string endpointName = message.Substring(17); INodeEndpointProtocolClient protocolClient = this.protocolFactory.CreateClient(); if (protocolClient.Connect("localhost/" + TcpShareProtocolFactory.GetInternalPipeAddress(port), endpointName, NodeEndpointProtocolFactoryExtension.DefaultTimeout)) { this.client = protocolClient; this.client.AddListener(new ResponseListener(this.server)); this.client.BeginListen(); request.Respond("[CONNECTED]"); return; } else { request.Respond("[CANNOTFINDENDPOINT]"); } } else { request.Respond("[ENDPOINTNOTCONNECTED]"); } this.server.Disconnect(); } else if (this.client.Connected) { this.client.Send(request.Message); } else { this.server.Disconnect(); } } }
private void ConnectionThreadProc(string address, string endpointName) { bool aborted = false; try { INodeEndpointProtocolClient client = this.Reflector.Factory.CreateClient(); if (client.Connect(address, endpointName, 5000)) { this.protocolClient = client; this.clientProvider = new ProtocolEnabledClientProvider(); this.clientProvider.Protocol = this.protocolClient; this.protocolClient.BeginListen(); } } catch (ThreadAbortException) { aborted = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Connecting Service"); } if (!aborted) { this.Invoke(new MethodInvoker(() => { if (this.clientProvider == null) { labelConnectionState.Text = "Failed to connect."; buttonConnect.Enabled = true; } else { labelConnectionState.Text = "Connected to the service."; buttonSend.Enabled = true; } this.connectionThread = null; })); } }
public static T WaitForClient <T>( this INodeEndpointProtocolFactory protocolFactory, string address, string endpointName, int timeout = DefaultTimeout ) where T : INodeEndpointClient { INodeEndpointProtocolClient client = protocolFactory.CreateClient(); if (client.Connect(address, endpointName, timeout)) { INodeEndpointClientProvider provider = new ProtocolEnabledClientProvider(); provider.Protocol = client; T endpointInterface = StrongTypedNodeEndpointClientBuilder.Create <T>(provider); client.BeginListen(); return(endpointInterface); } else { return(default(T)); } }
public void AttachClient(INodeEndpointProtocolClient client) { this.client = client; }
public virtual void OnInnerProtocolSet(INodeEndpointProtocolClient protocol) { this.innerProtocol = protocol; }
public virtual void SetOuterProtocol(INodeEndpointProtocolClient protocol) { throw new InvalidOperationException("The protocol client cannot have a outer protocol."); }
public void AttachClient(INodeEndpointProtocolClient client) { }