Tom Hall wrote:
I believe you are looking for the following:
IPEndPoint ep=new IPEndPoint(IPAddress.Parse("192.168.0.1"),2001);
Took me a while to figure that out too the first time.
Tom
"Dan" <an**@anon.com> wrote in message
news:aY********************@comcast.com...
I'm attempting to write a program in C# (with Whidbey) that communicates
with Half-Life based servers via UDP to grab server info (hostname,
players connected, map, etc). I'm using the UdpClient class to do so as of
now, however once I send the query string
("\u00ff\u00ff\u00ff\u00ffinfostring\u0000") I seem to get no response
back (it's set to accept responses from any IP), thus freezing the
program. Any ideas? I think it may have to do with the port, does anyone
know how to convert a string-based IP to a long so I can use one of the
overloads of the IPEndPoint constructor to set any port? Thanks.
Thanks, but it still doesn't work. Here's the culprit code, the app
locks up when it executes, I'm assuming because I'm getting no UDP
response. Also note that all vars used are declared at the top of the
parent class.
private void btnRefresh_Click(object sender, EventArgs e)
{
try
{
if (doneOnceSock == false)
{
byte[] sendBytes =
Encoding.ASCII.GetBytes("\u00ff\u00ff\u00ff\u00ffi nfostring\u0000");
csConn.Send(sendBytes, sendBytes.Length,
txtIP.Text, 27015);
IPEndPoint AnyIP = new
IPEndPoint(IPAddress.Parse(txtIP.Text), 0);
byte[] receiveBytes = csConn.Receive(ref AnyIP);
string returnData =
Encoding.ASCII.GetString(receiveBytes);
csConn.Close();
doneOnceSock = true;
}
else
{
sendBytes =
Encoding.ASCII.GetBytes("\u00ff\u00ff\u00ff\u00ffi nfostring\u0000");
csConn.Send(sendBytes, sendBytes.Length,
txtIP.Text, 27015);
AnyIP = new IPEndPoint(IPAddress.Parse(txtIP.Text), 0);
receiveBytes = csConn.Receive(ref AnyIP);
returnData = Encoding.ASCII.GetString(receiveBytes);
csConn.Close();
}
}
catch (Exception exc)
{
if (exc.Message == "An existing connection was forcibly
closed by the remote host")
{
MessageBox.Show("Invalid IP address or server busy.");
}
else
{
MessageBox.Show(exc.Message);
}
}
}