Control Panel
Forum
Hosting Help
ASP.NET 4 & SQL 2008 R2 Hosting
Resources
Notice
Login
Members
Shared Hosting
|
Upgrade
|
Advertise
|
Tutorials
|
AdSense revenue sharing sites
|
Exam 70-680 Practice Tests
|
Silverlight games
Total
members
:
210363
Average new registrations per day (in last 7 days):
16
New Registration:
Open
Register Now
Home
»
Questions & Answers
»
Connect to site
Connect to site
6/29/2010
Author:
Piotr F
Hi
How can i get IP and Port from www.aspspider.ws/MyStuff/ ?
My client application uses Socket class and need IP and Port to connect.
Or maybe there is some other method to connect?
Answers .............
Author:
irish
Posted Date: 7/28/2010
First method -
you'll add the System.Net namespace to your using section:
using System.Net;
Example of code to get address from hostname:
string howtogeek = www.aspspider.ws;
IPAddress[] addresslist = Dns.GetHostAddresses(howtogeek);
foreach (IPAddress theaddress in addresslist)
{
Console.WriteLine(theaddress.ToString());
}
Also try this method -
/ Signals when the resolve has finished.
public static ManualResetEvent GetHostEntryFinished =
new ManualResetEvent(false);
// Define the state object for the callback.
// Use hostName to correlate calls with the proper result.
public class ResolveState
{
string hostName;
IPHostEntry resolvedIPs;
public ResolveState(string host)
{
hostName = host;
}
public IPHostEntry IPs
{
get { return resolvedIPs; }
set {resolvedIPs = value;}}
public string host {get {return hostName;}
set {hostName = value;}}
}
// Record the IPs in the state object for later use.
public static void GetHostEntryCallback(IAsyncResult ar)
{
ResolveState ioContext = (ResolveState)ar.AsyncState;
ioContext.IPs = Dns.EndGetHostEntry(ar);
GetHostEntryFinished.Set();
}
// Determine the Internet Protocol (IP) addresses for
// this host asynchronously.
public static void DoGetHostEntryAsync(string hostname)
{
GetHostEntryFinished.Reset();
ResolveState ioContext= new ResolveState(hostname);
Dns.BeginGetHostEntry(ioContext.host,
new AsyncCallback(GetHostEntryCallback), ioContext);
// Wait here until the resolve completes (the callback
// calls .Set())
GetHostEntryFinished.WaitOne();
Console.WriteLine(EndGetHostEntry({0}) returns:, ioContext.host);
foreach (IPAddress ip in ioContext.IPs.AddressList)
{
Console.WriteLine( {0}, ip);
}
}
See this link:
http://msdn.microsoft.com/en-us/library/ms143989.aspx
Happy
coding
You must
login
to post answer for this question.
Advertise
Privacy Policy
Terms of use
Contact Us
SpiderWorks Technologies Pvt Ltd.
All Rights Reserved.