private void ValidateConstructorParameters(Type contractInterface, Type realProxyType, String channelId, AddressEndPoint remoteEp) { if (contractInterface == null) { ThrowHelper.ThrowArgumentNullException("contractInterface"); } if (realProxyType == null) { ThrowHelper.ThrowArgumentNullException("realProxyType"); } if (string.IsNullOrEmpty(channelId)) { ThrowHelper.ThrowArgumentNullException("channelId"); } if (!contractInterface.IsAssignableFrom(realProxyType)) { ThrowHelper.ThrowArgumentException("Provided client proxy does not implements the provided contract interface.", "realProxyType"); } if (remoteEp == null) { ThrowHelper.ThrowArgumentNullException("remoteEp"); } if (!ChannelServices.IsChannelRegistered(channelId)) { throw new ChannelNotFoundException(channelId); } ContractValidator.ValidateContractIntegrity(contractInterface); ImplementationValidator.ValidateProxyIntegration(realProxyType); this.mContractInterface = contractInterface; this.mRealProxyType = realProxyType; this.mChannel = ChannelServices.GetChannelById(channelId); this.mRemoteEndPoint = remoteEp; }
public ECommerceWebAppClient(string url, bool useHttps = false) { Requester requester = new Requester(url); Addresses = new AddressEndPoint(requester, "/api/myaccount/addresses", useHttps); Authentication = new AuthEndPoint(requester, "/SignInAttempt/CheckCredentials", useHttps); }
protected virtual Channel LookUpChannel() { Channel channel = ChannelServices.GetChannelById(this.ChannelId); if (channel == null) { // regisztrálás BinaryMessageSink sink = new BinaryMessageSink(true, 1024); List <IMessageSink> sinks = new List <IMessageSink>(); sinks.Add(sink); AddressEndPoint serverEndPoint = new AddressEndPoint("127.0.0.1", 0); List <AddressEndPoint> serverData = new List <AddressEndPoint>(); serverData.Add(serverEndPoint); TerraGrafNetworkFactory networkFactory = new TerraGrafNetworkFactory(); DefaultServerStreamFactory serverStreamFactory = new DefaultServerStreamFactory(); DefaultClientStreamFactory clientStreamFactory = new DefaultClientStreamFactory(); channel = new TCPChannel(this.ChannelId, sinks, sinks, serverData, networkFactory, serverStreamFactory, clientStreamFactory); channel.StartListening(); ChannelServices.RegisterChannel(channel); } return(channel); }
/// <summary> /// Begins the send. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="offset">The offset.</param> /// <param name="size">The size.</param> /// <param name="remoteEp">The remote ep.</param> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns> /// Async property /// </returns> public IAsyncResult BeginSend(byte[] buffer, int offset, int size, AddressEndPoint remoteEp, AsyncCallback callback, object state) { DoDisposeCheck(); if (buffer == null) { ThrowHelper.ThrowArgumentNullException("buffer"); } if ((offset < 0) || (offset > buffer.Length)) { ThrowHelper.ThrowArgumentOutOfRangeException("offset"); } if ((size < 0) || (size > (buffer.Length - offset))) { ThrowHelper.ThrowArgumentOutOfRangeException("size"); } Interlocked.Increment(ref mAsyncActiveUdpClientSendToCount); UdpClientSendToDelegate d = new UdpClientSendToDelegate(this.Send); if (this.mAsyncActiveUdpClientSendToEvent == null) { lock (LOCK_SENDTO) { if (this.mAsyncActiveUdpClientSendToEvent == null) { this.mAsyncActiveUdpClientSendToEvent = new AutoResetEvent(true); } } } this.mAsyncActiveUdpClientSendToEvent.WaitOne(); this.mUdpClientSendToDelegate = d; return(d.BeginInvoke(buffer, offset, size, remoteEp, callback, state)); }
/// <summary> /// Begins the receive. /// </summary> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns> /// Async property /// </returns> public IAsyncResult BeginReceive(AsyncCallback callback, object state) { DoDisposeCheck(); EndPoint any = new AddressEndPoint(AddressEndPoint.Any, 0); return(this.mClient.BeginReceiveFrom(mBuffer, 0, MAX_UDP_SIZE, ref any, callback, state)); }
/// <summary> /// Connects the specified local ep. /// </summary> /// <param name="localEp">The local ep.</param> public void Connect(AddressEndPoint localEp) { if (localEp == null) { ThrowHelper.ThrowArgumentNullException("localEp"); } Connect(localEp.Host, localEp.Port); }
/// <summary> /// Sends the specified buffer. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="size">The size.</param> /// <param name="remoteEp">The remote ep.</param> /// <returns>Number of sent bytes</returns> public int Send(byte[] buffer, int size, AddressEndPoint remoteEp) { if (buffer == null) { throw new ArgumentNullException("buffer"); } return(Send(buffer, 0, size)); }
/// <summary> /// Begins the send. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="remoteEp">The remote ep.</param> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns>Async property</returns> public IAsyncResult BeginSend(byte[] buffer, AddressEndPoint remoteEp, AsyncCallback callback, object state) { if (buffer == null) { ThrowHelper.ThrowArgumentNullException("buffer"); } return(BeginSend(buffer, 0, buffer.Length, callback, state)); }
/// <summary> /// Ends the receive. /// </summary> /// <param name="asyncResult">The async result.</param> /// <param name="remoteEp">The remote ep.</param> /// <returns>Received data</returns> public byte[] EndReceive(IAsyncResult asyncResult, ref AddressEndPoint remoteEp) { IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0); byte[] result = mUdpClient.EndReceive(asyncResult, ref endPoint); remoteEp = new AddressEndPoint(endPoint.Address.ToString(), endPoint.Port); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="TCPServer"/> class. /// </summary> /// <param name="endPoint">The end point.</param> internal TCPServer(AddressEndPoint endPoint) { if (endPoint == null) { ThrowHelper.ThrowArgumentNullException("endPoint"); } this.mEndPoint = endPoint; }
/// <summary> /// Initializes a new instance of the <see cref="ConnectionEntry"/> class. /// </summary> /// <param name="endPoint">The end point.</param> public ConnectionEntry(AddressEndPoint endPoint) { if (endPoint == null) { ThrowHelper.ThrowArgumentNullException("endPoint"); } this.mEndPoint = endPoint; }
/// <summary> /// Initializes a new instance of the <see cref="NATGateway"/> class. /// </summary> /// <param name="endPoint">The end point.</param> internal NATGateway(AddressEndPoint endPoint) { if (endPoint == null) { ThrowHelper.ThrowArgumentNullException("endPoint"); } this.mEndPoint = endPoint; }
/// <summary> /// Begins the connect. /// </summary> /// <param name="localEp">The local ep.</param> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns>Async property</returns> public IAsyncResult BeginConnect(AddressEndPoint localEp, AsyncCallback callback, object state) { if (localEp == null) { ThrowHelper.ThrowArgumentNullException("localEp"); } return(BeginConnect(localEp.Host, localEp.Port, callback, state)); }
/// <summary> /// Sends the specified buffer. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="remoteEp">The remote ep.</param> /// <returns> /// Number of sent bytes /// </returns> public int Send(byte[] buffer, AddressEndPoint remoteEp) { DoDisposeCheck(); if (buffer == null) { ThrowHelper.ThrowArgumentNullException("buffer"); } return(mClient.SendTo(buffer, remoteEp)); }
/// <summary> /// Initializes a new instance of the <see cref="UdpClient"/> class. /// </summary> /// <param name="port">The port where this instance will listen.</param> public UdpClient(int port) { if (!AddressEndPoint.ValidateTcpPort(port)) { ThrowHelper.ThrowArgumentOutOfRangeException("port"); } this.CreateClientSocket(); this.Connect(new AddressEndPoint(AddressEndPoint.Any, port)); }
/// <summary> /// Begins the send. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="size">The size.</param> /// <param name="remoteEp">The remote ep.</param> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns>Async property</returns> public IAsyncResult BeginSend(byte[] buffer, int size, AddressEndPoint remoteEp, AsyncCallback callback, object state) { if (buffer == null) { ThrowHelper.ThrowArgumentNullException("buffer"); } IPEndPoint ep = new IPEndPoint(Dns.GetHostAddresses(remoteEp.Host)[0], remoteEp.Port); return(mUdpClient.BeginSend(buffer, size, ep, callback, state)); }
public static void ParseArgs(string[] args) { Console.WriteLine("Control Module initialized. Parsing command line arguments..."); foreach (string arg in args) { List <string> arg_sep = Tools.ArgsParser(arg); string arg_name = arg_sep[0]; switch (arg_name) { case "config_file": config_file = arg_sep[1]; break; case "log": if (arg_sep[1] == "false") { FLAG_LOG = false; } if (arg_sep[1] == "true") { FLAG_LOG = true; } break; case "channel_hmi": EP_Route_HMI = new AddressEndPoint(arg_sep[1], Convert.ToInt16(arg_sep[2])); Console.WriteLine("Channel (HMI) endpoint: " + arg_sep[1] + ":" + arg_sep[2]); using_channel = true; break; case "channel_plant": EP_Route_Plant = new AddressEndPoint(arg_sep[1], Convert.ToInt16(arg_sep[2])); Console.WriteLine("Channel (Plant) endpoint: " + arg_sep[1] + ":" + arg_sep[2]); break; case "hmi_ep": EP_HMI = new ConnectionParameters(arg_sep[1], Convert.ToInt16(arg_sep[2]), Convert.ToInt16(arg_sep[3])); Console.WriteLine("HMI endpoint: " + arg_sep[1] + ":" + arg_sep[2]); break; case "plant_ep": EP_Plant = new ConnectionParameters(arg_sep[1], Convert.ToInt16(arg_sep[2]), Convert.ToInt16(arg_sep[3])); Console.WriteLine("Plant endpoint: " + arg_sep[1] + ":" + arg_sep[2]); break; default: Console.WriteLine("Unknown argument not used: " + arg_name); Console.WriteLine("Press any key to proceed..."); Console.ReadLine(); break; } } }
/// <summary> /// Initializes a new instance of the <see cref="ConnectionEntry"/> class. /// </summary> /// <param name="endPoint">The end point.</param> /// <param name="reconnectOnFailure">if set to <c>true</c> [reconnect on failure].</param> /// <param name="delayBetweenAttemptsInMS">The delay between attempts in MS.</param> /// <param name="connectionTimeout">The connection timeout.</param> public ConnectionEntry(AddressEndPoint endPoint, bool reconnectOnFailure, int delayBetweenAttemptsInMS, int connectionTimeout) : this(endPoint) { if (delayBetweenAttemptsInMS < 0) { ThrowHelper.ThrowArgumentOutOfRangeException("delayBetweenAttemptsInMS"); } this.mReconnectOnFailure = reconnectOnFailure; this.mDelayBetweenAttempsInMS = delayBetweenAttemptsInMS; this.mConnectionTimeout = connectionTimeout; }
/// <summary> /// UDP Broadcast, initializes a new instance of the <see cref="SocketRawDataMessage"/> class. /// </summary> /// <param name="senderId">The sender id.</param> /// <param name="senderPort">The sender port.</param> /// <param name="targetPort">The target port.</param> /// <param name="data">The data.</param> internal SocketRawDataMessage(string senderId, int senderPort, int targetPort, byte[] data) : base(senderId, string.Empty, MessageCodeEnum.SocketRawData, MessageTypeEnum.Udp, senderPort, targetPort, -1, -1) { if (data == null) { ThrowHelper.ThrowArgumentNullException("data"); } AddressEndPoint.ValidateTcpPort(senderPort); AddressEndPoint.ValidateTcpPort(targetPort); this.mData = data; }
/// <summary> /// Initializes a new instance of the <see cref="ProxyFactory<TContract>"/> class. /// </summary> /// <param name="channelId">The channel id.</param> /// <param name="realProxyType">Type of the real proxy.</param> /// <param name="remoteEp">The remote ep.</param> public ProxyFactory(string channelId, Type realProxyType, AddressEndPoint remoteEp) { if (string.IsNullOrEmpty(channelId)) { ThrowHelper.ThrowArgumentNullException("channelId"); } if (!typeof(ProxyBase).IsAssignableFrom(realProxyType)) { throw new InitializationException(String.Format("Provided real proxy type '{0}' does not inherits from {1} type.", realProxyType.FullName, typeof(ProxyBase).FullName)); } ValidateConstructorParameters(ContractInterface, realProxyType, channelId, remoteEp); }
public void ParseArgs(string[] args) { foreach (string arg in args) { List <string> arg_sep = Tools.ArgsParser(arg); if (arg_sep.Count() == 0) { continue; } string arg_name = arg_sep[0]; switch (arg_name) { case "config_file": config_file = arg_sep[1]; break; case "channel_controller": EP_Send_Controller = new AddressEndPoint(arg_sep[1], Convert.ToInt16(arg_sep[2])); using_channel = true; break; case "controller_ep": EP_Controller = new ConnectionParameters(arg_sep[1], Convert.ToInt16(arg_sep[2]), Convert.ToInt16(arg_sep[3])); break; case "log": if (arg_sep[1] == "false") { FLAG_LOG = false; } if (arg_sep[1] == "true") { FLAG_LOG = true; } break; case "log_file_name": log_file_name = "log_states_" + arg_sep[1] + ".txt"; break; case "ARG_INVALID": break; default: MessageBox.Show("Unknown argument: " + arg_name); break; } } }
/// <summary> /// Initializes a new instance of the <see cref="SocketOpenRequestMessage"/> class. /// </summary> /// <param name="senderId">The sender id.</param> /// <param name="targetId">The target id.</param> /// <param name="senderPort">The sender port.</param> /// <param name="targetPort">The target port.</param> /// <param name="senderSocketId">The sender socket id.</param> internal SocketOpenRequestMessage(string senderId, string targetId, int senderPort, int targetPort, long senderSocketId) : base(senderId, targetId, MessageCodeEnum.SocketOpenRequest, MessageTypeEnum.Tcp, senderPort, targetPort, senderSocketId, -1) { if (string.IsNullOrEmpty(targetId)) { ThrowHelper.ThrowArgumentNullException("targetId"); } AddressEndPoint.ValidateTcpPort(senderPort); AddressEndPoint.ValidateTcpPort(targetPort); if (senderSocketId < 1) { ThrowHelper.ThrowArgumentOutOfRangeException("senderSocketId"); } }
public void SendMessage(string EP_IP, int EP_port, string message, string sender_IP) { // append each sender>>destination pair to the end_points container (and checked listbox) AddressEndPoint EP = new AddressEndPoint(sender_IP + " >> " + EP_IP, EP_port); if (end_points.Contains(EP) == false) { end_points.Add(EP); clbDropOutTarget.Items.Add(EP); // manage the y-deviation in the plot end_point_ydev.Add(EP.ToString(), y_incr); y_incr += 0.04; } // initialize a sender Client Sender = new Client(EP_IP, EP_port); // add key Tools.AddKeyToDict(packet_timeseries, EP.ToString(), Constants.n_steps); // check if the end-point is checked or not (subject to packet drop-out or not) if (clbDropOutTarget.GetItemCheckState(clbDropOutTarget.Items.IndexOf(EP)) == CheckState.Checked) { // implement drop-out model MethodInfo isPass = SelectedDropOutModel.GetType().GetMethod("isPass"); bool pass = (bool)isPass.Invoke(SelectedDropOutModel, null); if (pass == true) { Sender.Send(message); // mark packet as passed packet_timeseries[EP.ToString()].InsertData(DateTime.UtcNow.ToString(Constants.FMT), (1 + end_point_ydev[EP.ToString()]).ToString()); } else { // mark packet as dropped packet_timeseries[EP.ToString()].InsertData(DateTime.UtcNow.ToString(Constants.FMT), (0 + end_point_ydev[EP.ToString()]).ToString()); } } else { // if the end-point is unchecked, pass the packet automatically Sender.Send(message); // mark packet as passed packet_timeseries[EP.ToString()].InsertData(DateTime.UtcNow.ToString(Constants.FMT), (1 + end_point_ydev[EP.ToString()]).ToString()); } }
private void SectionHandler_OnConfigurationChanged(object sender, EventArgs e) { CategoryPropertyItem piRoot = ConfigurationAccessHelper.GetCategoryPropertyByPath(TerraGrafConfiguration.Settings.CategoryPropertyItems, "NetworkPeering/NAT_Gateways"); List <AddressEndPoint> list = new List <AddressEndPoint>(); if (piRoot != null) { foreach (CategoryPropertyItem pi in piRoot) { list.Add(AddressEndPoint.Parse(pi.EntryValue)); } } EndPoints = list; }
private void btCreateServer_Click(object sender, EventArgs e) { int port = cbAutoPort.Checked ? 0 : Convert.ToInt32(nudPort.Value); AddressEndPoint aep = new AddressEndPoint(lvInterfaces.SelectedItems[0].Tag.ToString(), port); try { Wrapper.NetworkManager.StartServer(aep); this.Close(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Failed to create server.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Receives the specified remote ep. /// </summary> /// <param name="remoteEp">The remote ep.</param> /// <returns> /// Number of received bytes /// </returns> public byte[] Receive(ref AddressEndPoint remoteEp) { DoDisposeCheck(); if (remoteEp == null) { ThrowHelper.ThrowArgumentNullException("remoteEp"); } EndPoint refEp = new AddressEndPoint(AddressEndPoint.Any, 0); int count = mClient.ReceiveFrom(mBuffer, ref refEp); remoteEp = (AddressEndPoint)refEp; if (count < MAX_UDP_SIZE) { byte[] dst = new byte[count]; Buffer.BlockCopy(this.mBuffer, 0, dst, 0, count); return(dst); } return(this.mBuffer); }
/// <summary> /// Sends the specified buffer. /// </summary> /// <param name="buffer">The buffer.</param> /// <param name="offset">The offset.</param> /// <param name="size">The size.</param> /// <param name="remoteEp">The remote ep.</param> /// <returns> /// Number of sent bytes /// </returns> public int Send(byte[] buffer, int offset, int size, AddressEndPoint remoteEp) { DoDisposeCheck(); if (buffer == null) { ThrowHelper.ThrowArgumentNullException("buffer"); } if (remoteEp == null) { ThrowHelper.ThrowArgumentNullException("remoteEp"); } if (!mClient.IsBound) { this.Connect(new AddressEndPoint(AddressEndPoint.Any, 0)); } return(mClient.SendTo(buffer, offset, size, remoteEp)); }
/// <summary> /// Connects the specified local ep. /// </summary> /// <param name="localEp">The local ep.</param> public void Connect(AddressEndPoint localEp) { IPAddress a = null; if (localEp.Host.Equals(IPAddress.Any.ToString())) { a = IPAddress.Any; } else if (localEp.Host.Equals(IPAddress.IPv6Any.ToString())) { a = IPAddress.IPv6Any; } else { a = Dns.GetHostAddresses(localEp.Host)[0]; } mUdpClient.Connect(new IPEndPoint(a, localEp.Port)); mActive = true; }
/// <summary> /// Begins the connect. /// </summary> /// <param name="remoteEp">The remote ep.</param> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns>Async property</returns> public virtual IAsyncResult BeginConnect(AddressEndPoint remoteEp, AsyncCallback callback, object state) { Interlocked.Increment(ref mAsyncActiveConnectCount); ChannelConnectDelegate d = new ChannelConnectDelegate(this.Connect); if (this.mAsyncActiveConnectEvent == null) { lock (this) { if (this.mAsyncActiveConnectEvent == null) { this.mAsyncActiveConnectEvent = new AutoResetEvent(true); } } } this.mAsyncActiveConnectEvent.WaitOne(); this.mConnectDelegate = d; return(d.BeginInvoke(remoteEp, callback, state)); }
public ServiceProvider(INetworkPeer peer, AddressEndPoint ep, long priority, Dictionary <string, PropertyItem> properties) { if (peer == null) { ThrowHelper.ThrowArgumentNullException("peer"); } if (ep == null) { ThrowHelper.ThrowArgumentNullException("ep"); } if (priority < 0) { ThrowHelper.ThrowArgumentOutOfRangeException("priority"); } this.NetworkPeer = peer; this.RemoteEndPoint = ep; this.Priority = priority; this.mProperties = properties == null ? new Dictionary <string, PropertyItem>() : new Dictionary <string, PropertyItem>(properties); }