473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

UDP Communications

Dan
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.
Nov 16 '05 #1
3 5372
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.

Nov 16 '05 #2
Dan
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);
}
}
}
Nov 16 '05 #3
Oh, I see the problem, to prevent the GUI from hanging you need to launch
this on a separate thread because (from the docs)

The Receive method will block until a datagram arrives from a remote host.
When data is available, the Receive method will read the first enqueued
datagram and return the data portion as a byte array. This method populates
the remoteEP parameter with the IPAddress and port number of the sender.
So, it blocks (hangs) until it receives a packet. Check out threading in
the docs. A good place to look for code is

www.codeproject.com

Also, using a packet sniffer such as Ethereal www.ethereal.com is a great
way to find out what's really going on - I use it all the time debugging
protocols.

HTH

Tom

"Dan" <an**@anon.com> wrote in message
news:Pe********************@comcast.com...
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);
}
}
}

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dana Morris | last post by:
Call for Participation OMG's First Annual Software-Based Communications (SBC) Workshop: From Mobile to Agile Communications http://www.omg.org/news/meetings/SBC2004/call.htm September 13-16,...
4
by: Fan Ruo Xin | last post by:
I can truncate a version8 table by using "import from /dev/null ... replace into ..." when I use version8 client. But I failed to truncate the same table by using the same way if I connect from a...
1
by: Catherine Jo Morgan | last post by:
This is for a recreational tree climbing database. When a climb is arranged, it often begins with one or more inquiries by phone or email. Sometimes it takes several communications to answer...
3
by: rover | last post by:
I'm looking for information about using Access or vb/vba for serial communications to test devices or for alphanumieric paging. Please email if you can point me in the right direction. Thanks...
6
by: Peter Krikelis | last post by:
Hi All, I am having a problem setting up input mode for serial communications. (Sorry about the long code post). The following code is what I use to set up my comm port.
4
by: Paul Baker | last post by:
Hello All, This is my first post so apologies if this is the wrong newsgroup. I'm designing software for a platform that will sit on a CAN bus. There will be three separate programs running...
4
by: Gary Frank | last post by:
I'd like to write a program in VB.Net that handles serial communications to several devices. VB.Net 2003 does not have adequate built-in serial communications. I heard that 2005 will have that. ...
8
by: Sharon | last post by:
Hi all. How can i secure socket communications? Is it possible to use ssl? Thanks, Sharon.
8
by: vicky | last post by:
Hello,I met a question when I wrote the program.I want the program can transmit the data frame continuosly through the RS232 when the communication has been interrupted.But I don't know how to...
5
by: Franklin M. Gauer III | last post by:
Hi All, I've written an ASP.NET application (webservice) that does simple serial communications via the .NET 2.0 SerialComm object. The application runs fine on my development machine. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.