|
I am attempting to synchronize my system clock with an NTP server using SNTP. I have found a number of publicly available NTP servers hosted by NIST and affiliates here[^]. I also found a reference to the type of message I will receive from the server here[^]. However, I don't know how to get this response from the server. Does anyone have experience with something like this that he or she will share with me? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I found the answer... you send a byte array with 48 empty bytes as a udp client, then listen with the same client for a response. The code is as follows, where m_ep is the IpEndpoint of a NTP server (port 123):
private static readonly IPEndPoint MY_IPEP = new IPEndPoint(IPAddress.Any, 0);
private void GetTime(object clientObj) {
UdpClient client = (UdpClient)clientObj;
byte[] result = client.Receive(ref m_ep);
...
}
private void button1_Click(object sender, EventArgs e) {
UdpClient client = new UdpClient();
client.Client.Bind(MY_IPEP);
new Thread(new ParameterizedThreadStart(GetTime)).Start(client);
byte[] message = new byte[48];
message[0] = 0x1B;
client.Send(message, 48, m_ep);
} Hope this helps someone.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I have an access db. Tables have a YES/NO check box as the "NEW ITEM" column, I want to count how many new items are in the db. and print it.
I am connected to the db, how can i count ?
DataAccess da = new DataAccess();
//Choose the table
string sql = "SELECT * FROM read WHERE New?=true ";
and wanna print it as:
You have" + " " + i.ToString()+ " " + "clients waiting";
thanks
|
|
|
|
|
To get a count using SQL you would do this
SELECT COUNT(*) FROM read WHERE New?=true
This will return a single scalar value
only two letters away from being an asset
|
|
|
|
|
|
Hi,
I hope someone can help me here. We have a 3rd party windows application that is written in .NET 2 and want to prohibit users from being able to use on of the features which seems like a simple print screen from a right click on a list of contacts. The problem is I am a fairly novice C# coder but it has become my problem!
I guess that I would need to somehow capture a win32 API onPrint() event but the problem is I have absoloutly no idea about how one would go abouts doing this. I think it would be a very important step in my learning if I could understand how I could create a custom event handle to a win32 API call.
Does anyone have any ideas on how I could do this or where I could find articles on this? I read one article but it went quite over the top of my head and did not seem to work on XP sp2 or vista machines.
Cheers,
Viv
|
|
|
|
|
You want to prevent printing from a third party app? Unless you have the code for this app and modify it, the only other way is to somehow hook into the app, which isn't easy even for experienced people, let alone a novice.
only two letters away from being an asset
|
|
|
|
|
I have different types of objects stored in a xml file. I am wondering what is the fastest/best way to read this file. I mean, should i go line by line or should i read as an object. If reading as an object reduces extract codes then can somebody provides me a simple example.
thanks for answering
|
|
|
|
|
You can use the XmlDocument object to read elements in an XML file.
<br />
System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();<br />
<br />
xmlDocument.Load(filePath);<br />
<br />
|
|
|
|
|
There is no "best" way, but there are at least 3 different ways depending on the circumstance.
1) Use XmlDocument as described above. This allows you read/write access to the Xml file and is therefore generally the slowest.
2) Use an XmlTextReader gives you forward-only read access.
3) use XmlSerializer to turn an object graph into an object. This could well be the "fastest" but it would depend entirely on your object.
|
|
|
|
|
XLINQ? (XDocument )
|
|
|
|
|
If you have LINQ availale in your .net / vs version - use it! It takes a bit of getting used to, but so far I have found it to be far simpler than using XmlDocuments, readers, Xpath etc...
using System.Linq;
using System.Xml.Linq;
will change (for the better) the way you work with xml!
|
|
|
|
|
Hi guys,
I have a datagridview. i can delete all rows, bud not the last row, i mean i can't never delete wen there is only one row remaind.
any idea how to fix this?
thanx.
|
|
|
|
|
Can you post your code?
------------------------------------------------------------
"The only true wisdom is in knowing you know nothing." --Socrates
|
|
|
|
|
da_imp = new DataAdapter(sqlcommand);<br />
SqlCommandBuilder cb_imp = new SqlCommandBuilder(da_imp);<br />
da_imp.Update(dt_imp);
|
|
|
|
|
I have a desktop application, where you have a link to start the web application. The web application uses a ms access db to retrieve data from.
Now what I want to add is, a "next" button on the desktop app, to get the next row on the ms access to be retrieved and printed to the web applications.
right now the web app get the data on page_Load
public void Page_Load(Object sender, EventArgs E)
{
DataAccess da = new DataAccess();
//Choose the table
string sql = " SELECT * FROM readfrm";
DataSet result = da.GetDataSet(sql);
int size = result.Tables[0].Rows.Count;
// string txtName.Text;
txtName.Text = result.Tables[0].Rows[0]["Name"].ToString();
How can I retrieve the next row on db readfrm by a next button on my desktop app ? The reason is desktop app is a small notification window which is trigerred by some event to tell you there are new rows added to the db, and by clicking on it or clicking on next you will see whats new on the db.
Thanks
|
|
|
|
|
I'm not entirely sure how your desktop and web app are set up, but this is how I would do it.
Assuming that your Desktop app knows about the new record(s) that you want to display in the Web app (for example, it knows the ID of the new record), I would have the link that points to the Web app have a querystring value for the ID of the record to open in the Web app.
The URL in the link will looks something like http://mydomain.com/ShowMeTheNewRecord.aspx?id=New_ID_From_Desktop_App_Goes_Here
Obviously New_ID_From_Desktop_App_Goes_Here will be replaced with the identifier for that record in the database. Then you can check in your page load to see if there is a querystring value, and if there is, load the corresponding record in your webform.
Hope I didn't confuse you...
|
|
|
|
|
How do I programmatically get a list of users in an ActiveDirectory group? A google search has shown up several ways of doing it, none of which I can get to work and none of which seem to agree with each other. Is there a definitive way to, say, get a list of users of a group called, for example, Sales?
|
|
|
|
|
Did you search codeproject? There is one article which explains how to do anything with active directory
|
|
|
|
|
I've tried several articles on here and about 50 which Google has shown up. It might be that I have spent so long on this the answer will just pass me by now. I just want a list of user names from a group to populate a listbox. Creating and editing a text file to hold the data is looking very attractive right now.
|
|
|
|
|
A bit of venting always works
http://www.codeproject.com/KB/system/QueryADwithDotNet.aspx[^]">
|
|
|
|
|
How do I get string data into a byte array, programmatically, without doing a hex conversion. i.e.,
byte[i] = (???)string.Substring(0,2);
I need the programmatic equivelent of:
byte[] bytes = {0x14, 0x55, 0x90, 0x00, 0x01}; or
byte[i] = {0x + string}
I can't make any of this work. Need Guru!
TIA,
Steve
|
|
|
|
|
Hi there,
Maybe this will put you in the right track:
string StringToConvert = "abc";<br />
byte[] bytes = StringToByteArray(StringToConvert);<br />
<br />
private byte[] StringToByteArray(string str)<br />
{<br />
char[] chars = str.ToCharArray();<br />
byte[] bytes = Array.ConvertAll<char, byte="">(chars, new Converter<char, byte="">(CharToByte));<br />
return bytes;<br />
}<br />
private byte CharToByte(char ch) { return (byte)ch; }</char,></char,>
Hope it helps.
Danny
|
|
|
|
|
Hi Danny,
This looks like what I'm after except I'm getting two errors when implemented:
Error 1 Using the generic type 'System.Converter<tinput,toutput>' requires '2' type arguments
Error 2 The type arguments for method 'System.Array.ConvertAll<tinput,toutput>(TInput[], System.Converter<tinput,toutput>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
What did I do wrong?</tinput,toutput></tinput,toutput></tinput,toutput>
|
|
|
|
|
Sorry, I guess the pasting went wrong, the function should look like this:
private byte[] StringToByteArray(string str)
{
char[] chars = str.ToCharArray();
byte[] bytes = Array.ConvertAll<char, byte>(chars, new Converter<char, byte>(CharToByte));
return bytes;
}
|
|
|
|