Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client / Server

Status
Not open for further replies.

stuartd

Programmer
Jan 8, 2001
146
US
Hi,

I want to write a server program accepting socket connections.

So far i have:
my_socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
g_ws.Bind(ENDPOINT);
g_ws.Listen(10);

So i need an ENDPOINT to bind - so far i have:
IPEndPoint ep; ep=new IPEndPoint(ADDRESS,6543);

where ADDRESS is a long or byte[] - (this is where i am stuck)

How do i get the required ip address (eg 192.168.6.16) to a long or byte[]?


SD
 
If you only have one NIC in the machine, you can use IPAddress.Any as your parameter.

If you have multiple NICs in the machine, you'll need to specify which one (more than likely), so you'll do a Dns.GetHostByName, which returns a IPHostEntry object, which contains an AddressList property, each of which is an IPAddress for your NICs.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
So how do i get the required ip address (eg 192.168.6.16) to a long or byte[] if i want to do it by hand?
(eg a client connecting to the server)


SD
 
Code:
IPAddress ipAd = IPAddress.Parse("192.168.6.16")
I have a server program which uses that line to parse the IpAddress into a useable form. You can try that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top