1 //==========================================================================
4 // Summary: Implements Helper internal class for transmission over HTTP.
6 // Classes: internal HttpHelper
9 // Ahmad Tantawy popsito82@hotmail.com
10 // Ahmad Kadry kadrianoz@hotmail.com
11 // Hussein Mehanna hussein_mehanna@hotmail.com
13 //==========================================================================
19 using System.Text.RegularExpressions;
21 namespace System.Runtime.Remoting.Channels.Http
23 internal class HttpHelper
26 public static string Parse(string URL , out string ObjectURI)
33 if(StartsWithHttp(URL))
35 Pos = URL.IndexOf("/",7);
39 Pos = URL.IndexOf("/",0);
44 ObjectURI = URL.Substring(Pos);
45 return URL.Substring(0,Pos);
51 public static bool StartsWithHttp(string URL)
53 if(URL.StartsWith("http://"))
59 public static Stream CopyStream(Stream inStream)
62 Stream outStream = new MemoryStream();
70 temp = inStream.ReadByte();
73 outStream.WriteByte((byte)temp);
76 outStream.Seek(0,SeekOrigin.Begin);
85 public static bool CopyStream(Stream inStream,ref Stream outStream)
93 f = new FileStream("f.txt",System.IO.FileMode.Create);
97 temp = inStream.ReadByte();
101 f.WriteByte((byte)temp);
106 outStream.WriteByte((byte)temp);
113 if(outStream.CanSeek)
114 outStream.Seek(0,SeekOrigin.Begin);
118 Console.WriteLine(e);
126 public static String GetHostName()
128 string hostName = Dns.GetHostName();
130 if (hostName == null)
132 throw new ArgumentNullException("hostName");
138 public static String GetMachineName()
141 String machineName = GetHostName();
142 if (machineName != null)
143 machineName= Dns.GetHostByName(machineName).HostName;
145 if (machineName== null)
147 throw new ArgumentNullException("machine");
153 public static String GetMachineIp()
156 String hostName = GetMachineName();
157 String MachineIp=null;
159 IPHostEntry Entries = Dns.GetHostByName(hostName);
160 if ((Entries.AddressList.Length > 0)&&(Entries != null))
162 MachineIp = Entries.AddressList[0].ToString();
165 if (MachineIp == null)
167 throw new ArgumentNullException("ip");