示例#1
0
 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();
 }
示例#2
0
 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");
     }
 }
示例#3
0
 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);
 }
示例#4
0
 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");
     }
 }
示例#5
0
 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);
 }
示例#6
0
 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");
     }
 }
示例#7
0
 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");
     }
 }
示例#8
0
 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");
     }
 }
示例#9
0
 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");
     }
 }
示例#10
0
 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();
 }
示例#11
0
 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);
 }
示例#12
0
 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");
     }
 }
示例#13
0
 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();
 }
示例#14
0
 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);
 }
示例#15
0
 public static PhysicalAddress GetMAC()
 {
     return(MiMFa_Net.GetMAC());
 }
示例#16
0
 public static List <PhysicalAddress> GetMACs()
 {
     return(MiMFa_Net.GetMACs());
 }
示例#17
0
 public static IPAddress GetInternalIPv6(string hostName = null)
 {
     return(MiMFa_Net.GetInternalIPv6(hostName));
 }
示例#18
0
 public static List <IPAddress> GetInternalIPs(string hostName = null)
 {
     return(MiMFa_Net.GetInternalIPs(hostName));
 }
示例#19
0
 public static string GetHostName()
 {
     return(MiMFa_Net.GetHostName());
 }
示例#20
0
 public static IPAddress GetExternalIP(string url)
 {
     return(MiMFa_Net.GetExternalIP(url));
 }
示例#21
0
        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();
        }