August 10th, 2009 Phanix
UDP Server
private void ServerBroadcastThread()
{
int GroupPort = 15000;
UdpClient udp = new UdpClient();
udp.EnableBroadcast = true;
IPEndPoint groupEP = new IPEndPoint(IPAddress.Broadcast, GroupPort);
string str4;
byte[] sendBytes4;
while (true)
{
str4 = "Is anyone out there?";
sendBytes4 = Encoding.Default.GetBytes(str4);
udp.Send(sendBytes4, sendBytes4.Length, groupEP);
Thread.Sleep(10000);
}
}
UDP Client
private void ClientBroadcastThread()
{
UdpClient receivingUdpClient = new UdpClient(15000);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
string returnData;
byte[] receiveBytes;
while (true)
{
try
{
// Blocks until a message returns on this socket from a remote host.
receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint);
returnData = Encoding.ASCII.GetString(receiveBytes);
MessageBox.Show(returnData);
}
catch (Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
Posted in 學習工作, 程式 | No Comments »
August 7th, 2009 Phanix
While using some library functions in Visual Studio .NET, you can always find such kind of descriptions which help you to get some idea of parameters and functions.

However, how to provide such kind of descriptions in your class libraries?
Plz refer this! http://www.codeproject.com/KB/XML/csharpcodedocumentation.aspx?msg=1643354
Posted in 學習工作, 程式 | No Comments »
August 7th, 2009 Phanix
While using MySQL ODBC to execute sql statements, only single sql statement is allowed for execution by default. If you want to execute multiple sql statements at once, you have to enable the multiple statements setting in MySQL ODBC.

Posted in 學習工作, 程式 | No Comments »
July 30th, 2009 Phanix
程式執行後以最小化的方式執行,即不會出現在工作列上,而會出現在tray裡頭。而在 tray icon 上可以點滑鼠右鍵來彈出功能表單(menu),進行各功能選擇(如結束等)。
Read the rest of this entry / 繼續閱讀 »
Posted in 學習工作, 工作, 程式 | No Comments »
July 15th, 2009 Phanix
有時候為了要偷偷做一些事情, 所以會想要讓程式以無視窗在背景執行, 而要做出這樣的程式其實方法很簡單
- 在建立專案的時候選擇「主控台應用程式」(console application)
- 設定專案屬性(properties), 將輸出類型改為「windows 應用程式」
這樣就可以了, 當發現到這樣做就搞定的時候還有點訝異怎麼這麼容易…
Posted in 學習工作, 工作, 程式 | No Comments »
July 1st, 2009 Phanix
那個\0很重要。
using System.Runtime.InteropServices;
public bool DoDBConnect(string strDSN,string strUID,string strPWD)
{
try
{
strConn = "DSN=" + strDSN + ";UID=" + strUID + ";PWD=" + strPWD + ";";
cn = new OdbcConnection(strConn);
cmd = new OdbcCommand();
adp = new OdbcDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = cn;
}
catch
{
return false;
}
return true;
}
[
DllImport("ODBCCP32.dll")
]
private static extern bool SQLConfigDataSource(IntPtr hwndParent, int fRequest, string lpszDriver, string lpszAttributes);
public bool CreateODBCDSN(string strDSN, string strServer, string strDB, string strDescription)
{
string strSQL = "SERVER=" + strServer + "\0";
strSQL += "DESCRIPTION=" + strDescription + "\0";
strSQL += "DSN=" + strDSN + "\0";
strSQL += "DATABASE=" + strDB + "\0";
strSQL += "trusted_connection=no\0";
return SQLConfigDataSource((IntPtr)0, 4, "SQL Server", strSQL);
}
Posted in 學習工作, 程式 | No Comments »
June 30th, 2009 Phanix
原本以為在 C# 中使用 struct 又要匯出成 .dll 給 c++ 需要有什麼特殊處理,結果發現其實不用…
namespace TESTCOMObject
{
//其他程式碼
//...
public struct tag_Data
{
public string strName;
public string strValue;
}
}
而在 C++ 裡頭要使用就只要 import 之後就可以放心用了
TESTCOMObject::tag_Data aa[50];
aa[7].strName = "xxabc";
aa[7].strValue = "oo";
aa[17].strName = "xxabcyy";
aa[17].strValue = "oo";
TESTCOMObject::tag_Data bb;
bb.strName = "hahaha";
bb.strValue = "hehehe";
Posted in 學習工作, 程式 | No Comments »
June 29th, 2009 Phanix
有點繁瑣的方式,全部需要三個檔案來完成。
Read the rest of this entry / 繼續閱讀 »
Posted in 學習工作, 程式 | No Comments »
May 9th, 2009 Phanix
處理 XML 文件資料時,利用 XPath 來選取文件中節點是蠻常見的方式,可是當這個節點是具有 namespace 時,該怎麼辦呢?
Read the rest of this entry / 繼續閱讀 »
Posted in 學習工作, 工作, 研究, 程式 | No Comments »
January 9th, 2009 Phanix
Remeber to check the item “Integration Services” (SSIS) in the install process, or you will fail and get a error message like “product level is insufficient for components” while importing data from txt, excel, etc. files into a SQL server 2005 database.
Related: porduct level is insufficient for components
Posted in 學習工作, 工作, 研究, 程式, 軟體, 電腦網路 | No Comments »