By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,900 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,900 IT Pros & Developers. It's quick & easy.

What is wrong with this TCP/IP s.bind?

P: n/a
I keep getting the same error code on s.bind:
{"The requested address is not valid in its context" }.
Here is the code that produces the error:
IPHostEntry hostEntry = Dns.Resolve("NPIFA21AE");
IPEndPoint endPoint = new IPEndPoint(hostEntry.AddressList[0],
9100);

Socket s = new Socket(endPoint.Address.AddressFamily,
SocketType.Dgram,
ProtocolType.Udp);

// Creates an IPEndPoint to capture the identity of the sending
host.
IPEndPoint sender = new IPEndPoint(hostEntry.AddressList[0], 9100);
EndPoint senderRemote = (EndPoint)sender;

// Binding is required with ReceiveFrom calls.

try
{
s.Bind(endPoint);
}
catch (Exception e)
{
Console.WriteLine("Winsock error: " + e.ToString());
}

//s.Bind(endPoint);

byte[] msg = new Byte[1256];
// Console.WriteLine ("Waiting to receive datagrams from client...");

// This call blocks.
s.ReceiveFrom(msg, ref senderRemote);
s.Close();
Any help is appreciated.
Thanks,
Trint

Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.