public void Start(string interlocutorAddress) { string[] sa = interlocutorAddress.Split(':'); InterlocutorHostName = sa[0].Trim(); if (sa.Length > 1) { Port = int.Parse(sa[1].Trim()); } try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { try { InterlocutorIP = IPAddress.Parse(InterlocutorHostName); } catch { InterlocutorIP = null; } } Start(); }
public void Receive() { if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName)) { try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { } } if (InterlocutorIP != null) { TcpListener listener = new TcpListener(InterlocutorIP, Port); listener.Start(); ConnectedToInterlocutor(InterlocutorIPEndPoint); while (Run) { TcpClient client = listener.AcceptTcpClient(); StartDownloadData(null, InterlocutorIPEndPoint, 0); NetworkStream strm = client.GetStream(); BinaryFormatter formatter = new BinaryFormatter(); EndDownloadData(formatter.Deserialize(strm), InterlocutorIPEndPoint, client.ReceiveBufferSize); strm.Close(); client.Close(); } listener.Stop(); StopDownloadData(null, InterlocutorIPEndPoint, 0); } else { throw new ArgumentException("Not set IP or HostName"); } }
public void Send(object obj, string interlocutorAddress) { string[] sa = interlocutorAddress.Split(':'); SenderInterlocutorHostName = sa[0].Trim(); if (sa.Length > 1) { SenderPort = int.Parse(sa[1].Trim()); } try { SenderInterlocutorIP = MiMFa_Net.GetInternalIPv4(SenderInterlocutorHostName); } catch { try { SenderInterlocutorIP = IPAddress.Parse(SenderInterlocutorHostName); } catch { SenderInterlocutorIP = null; } } Send(obj); }
public void SocketSend(object obj) { if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName)) { try { InterlocutorIP = IPAddress.Parse(InterlocutorHostName); } catch { try { InterlocutorIP = MiMFa_Net.GetExternalIP(InterlocutorHostName); } catch { } } } if (InterlocutorIP != null) { TcpClient client = new TcpClient(); client.Connect(InterlocutorIP, Port); ConnectedToInterlocutor(InterlocutorIPEndPoint); Stream stream = client.GetStream(); StartUploadData(obj, InterlocutorIPEndPoint, 0); byte[] bytarr = (obj != null && obj is byte[]) ? (byte[])obj : MiMFa_IOService.Serialize(obj); stream.Write(bytarr, 0, bytarr.Length); client.Close(); EndUploadData(obj, InterlocutorIPEndPoint, bytarr.Length); } else { throw new ArgumentException("Not set IP or HostName"); } }
public void Receive(string remoteFileAddress, string interlocutorAddress) { string[] sa = interlocutorAddress.Split(':'); ReceiverInterlocutorHostName = sa[0].Trim(); if (sa.Length > 1) { ReceiverPort = int.Parse(sa[1].Trim()); } try { ReceiverInterlocutorIP = MiMFa_Net.GetInternalIPv4(ReceiverInterlocutorHostName); } catch { try { ReceiverInterlocutorIP = IPAddress.Parse(ReceiverInterlocutorHostName); } catch { ReceiverInterlocutorIP = null; } } Receive(remoteFileAddress); }
public void Send(object obj) { if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName)) { try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { } } if (InterlocutorIP != null) { TcpClient client = new TcpClient(new IPEndPoint(InterlocutorIP, Port)); // have my connection established with a Tcp Server ConnectedToInterlocutor(InterlocutorIPEndPoint); client.SendTimeout = SendTimeout; client.ReceiveTimeout = ReceiveTimeout; NetworkStream strm = client.GetStream(); // the stream StartUploadData(obj, InterlocutorIPEndPoint, 0); IFormatter formatter = new BinaryFormatter(); // the formatter that will serialize my object on my stream formatter.Serialize(strm, obj); // the serialization process strm.Close(); client.Close(); EndUploadData(obj, InterlocutorIPEndPoint, strm.Length); } else { throw new ArgumentException("Not set IP or HostName"); } }
public void SocketReceive() { if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName)) { try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { } } if (InterlocutorIP != null) { TcpListener listener = new TcpListener(InterlocutorIP, Port); listener.Start(); ConnectedToInterlocutor(InterlocutorIPEndPoint); while (Run) { Socket socket = listener.AcceptSocket(); byte[] bytarr = new byte[BufferSize]; StartDownloadData(null, InterlocutorIPEndPoint, 0); int mi = socket.Receive(bytarr); bool b = mi > 0; if (b && EndDownloadData != null) { EndDownloadData(MiMFa_IOService.Deserialize(bytarr), InterlocutorIPEndPoint, mi); } socket.Close(); } listener.Stop(); StopDownloadData(null, InterlocutorIPEndPoint, 0); } else { throw new ArgumentException("Not set IP or HostName"); } }
public void Start() { if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName)) { try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { } } if (InterlocutorIP == null) { InterlocutorIP = IPAddress.Any; } if (InterlocutorIP != null) { SocketPermission Permission; // Creates one SocketPermission object for access restrictions Permission = new SocketPermission( NetworkAccess.Accept, // Allowed to accept connections TransType, // Defines transport types "", // The IP addresses of local host SocketPermission.AllPorts // Specifies all ports ); // Listening Socket object Listener = null; // Ensures the code to have permission to access a Socket Permission.Demand(); // Create one Socket object to listen the incoming connection Listener = new Socket( InterlocutorIP.AddressFamily, SocketType.Stream, ProtType ); // Associates a Socket with a local endpoint Listener.ReceiveTimeout = Timeout; Listener.Bind(InterlocutorIPEndPoint); ConnectedToInterlocutor(InterlocutorIPEndPoint); // Places a Socket in a listening state and specifies the maximum // Length of the pending connections queue Listener.Listen(PendingQueueLength); // Begins an asynchronous operation to accept an attempt ListeningToInterlocutor(InterlocutorIPEndPoint); if (Run) { Listener.BeginAccept(new AsyncCallback(AcceptCallback), Listener); } } else { throw new ArgumentException("Not set IP or HostName"); } }
public void Receive(string remoteFileAddress) { if (SenderInterlocutorIP == null && !string.IsNullOrEmpty(SenderInterlocutorHostName)) { try { SenderInterlocutorIP = MiMFa_Net.GetInternalIPv4(SenderInterlocutorHostName); } catch { } } if (SenderInterlocutorIP != null) { string la = LocalTempDirectory + Path.GetFileName(remoteFileAddress); FTP.Download(la, remoteFileAddress); } else { throw new ArgumentException("Not set IP or HostName"); } }
public void SocketReceive(object obj, string interlocutorHostName, int port) { InterlocutorHostName = interlocutorHostName.Trim(); Port = port; try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { try { InterlocutorIP = IPAddress.Parse(InterlocutorHostName); } catch { InterlocutorIP = null; } } SocketReceive(); }
public void Receive(string remoteFileAddress, string interlocutorHostName, int port) { ReceiverInterlocutorHostName = interlocutorHostName.Trim(); ReceiverPort = port; try { ReceiverInterlocutorIP = MiMFa_Net.GetInternalIPv4(ReceiverInterlocutorHostName); } catch { try { ReceiverInterlocutorIP = IPAddress.Parse(ReceiverInterlocutorHostName); } catch { ReceiverInterlocutorIP = null; } } Receive(remoteFileAddress); }
public void Send(string fileAddress) { if (SenderInterlocutorIP == null && !string.IsNullOrEmpty(SenderInterlocutorHostName)) { try { SenderInterlocutorIP = MiMFa_Net.GetInternalIPv4(SenderInterlocutorHostName); } catch { } } if (SenderInterlocutorIP != null) { string ra = RemoteTempDirectory + Path.GetFileName(fileAddress); FTP.Upload(fileAddress, ra); Sender.Start(ra, SenderInterlocutorIPEndPoint); } else { throw new ArgumentException("Not set IP or HostName"); } }
public void Start(string interlocutorHostName, int port) { InterlocutorHostName = interlocutorHostName.Trim(); Port = port; try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { try { InterlocutorIP = IPAddress.Parse(InterlocutorHostName); } catch { InterlocutorIP = null; } } Start(); }
public void Send(object obj, string interlocutorHostName, int port) { SenderInterlocutorHostName = interlocutorHostName.Trim(); SenderPort = port; try { SenderInterlocutorIP = MiMFa_Net.GetInternalIPv4(SenderInterlocutorHostName); } catch { try { SenderInterlocutorIP = IPAddress.Parse(SenderInterlocutorHostName); } catch { SenderInterlocutorIP = null; } } Send(obj); }
public static PhysicalAddress GetMAC() { return(MiMFa_Net.GetMAC()); }
public static List <PhysicalAddress> GetMACs() { return(MiMFa_Net.GetMACs()); }
public static IPAddress GetInternalIPv6(string hostName = null) { return(MiMFa_Net.GetInternalIPv6(hostName)); }
public static List <IPAddress> GetInternalIPs(string hostName = null) { return(MiMFa_Net.GetInternalIPs(hostName)); }
public static string GetHostName() { return(MiMFa_Net.GetHostName()); }
public static IPAddress GetExternalIP(string url) { return(MiMFa_Net.GetExternalIP(url)); }
public void Start(object obj) { Thread th = new Thread(() => { try { if (InterlocutorIP == null && !string.IsNullOrEmpty(InterlocutorHostName)) { try { InterlocutorIP = MiMFa_Net.GetInternalIPv4(InterlocutorHostName); } catch { } } if (InterlocutorIP != null) { StartSendData(obj, InterlocutorIPEndPoint, 0); SocketPermission Permission; // Creates one SocketPermission object for access restrictions Permission = new SocketPermission( NetworkAccess.Accept, // Allowed to accept connections TransType, // Defines transport types "", // The IP addresses of local host SocketPermission.AllPorts // Specifies all ports ); // Listening Socket object SenderSock = null; // Ensures the code to have permission to access a Socket Permission.Demand(); // Create one Socket object to listen the incoming connection SenderSock = new Socket( InterlocutorIP.AddressFamily, SocketType.Stream, ProtocolType.Tcp ); // Associates a Socket with a local endpoint SenderSock.SendTimeout = Timeout; SenderSock.Connect(InterlocutorIPEndPoint); ConnectedToInterlocutor(InterlocutorIPEndPoint); // Places a Socket in a listening state and specifies the maximum // Length of the pending connections queue // Sending message byte[] data = (obj != null && obj is byte[]) ? (byte[])obj : MiMFa_IOService.Serialize(obj); // Sends data to a connected Socket. int bytesSend = SenderSock.Send(data); EndSendData(data, InterlocutorIPEndPoint, bytesSend); Receive(); } else { throw new ArgumentException("Not set IP or HostName"); } } catch (Exception ex) { ErrorSendData(obj, InterlocutorIPEndPoint, 0, ex); } }); th.IsBackground = true; th.Start(); }