|
I need to know how would i remotely call methods on another pc(program) when my database(sql) changes(update occurs).I need to notify my viewing program(GUI) of the changes allowing immediatly show the changes as the database changes. How would this be done in C#. Triggers? I am very new to C# links to some nice tuts would be helpful as well as any other suggestions on how i would tackle this. Thank you
|
|
|
|
|
There are plenty of ways I'm sure, but I've always had the best success with custom TCP protocols. Meaning, you would connect to the remote computer through a TCP Client on a dedicated port, and send your own message format to the remote computer. The remote computer should have a thread that is constantly listening on that port for new connections. When it receives your connection, it verifies that it came from you (your custom message format should have a username/password in it), and performs the necessary operation based on the message. This approach has yet to fail me.
|
|
|
|
|
that sound great, is there perhaps some links to samples explaining in more detail, as i said i am new to programming. thanx again
|
|
|
|
|
If you've never set up a TcpClient, studio 2005 makes it pretty easy. Same for the TcpListener on the remote computer.
//DataBase Computer
TcpClient m_connection = new TcpClient("15.3.6.33", 17534);
StreamWriter m_writer = m_connection.GetStream();
m_writer.WriteLine("(app)(username)mel(/username)(password)mel(/password)" +
"(command)REFRESH(/command)(/app)");
//Remote Computer
TcpListener m_listener = new TcpListener(17534);
TcpClient m_connection;
StreamReader m_reader;
String strCommandText;
m_listener.Start();
while(true)
{
if (m_listener.Pending())
{
m_connection = m_listener.AcceptTcpClient();
m_reader = m_connection.GetStream();
strCommandText = m_reader.ReadLine();
// Now parse your message to find out what you should do.
}
}
-- modified at 18:16 Tuesday 30th August, 2005
|
|
|
|
|
Hi there,
I'm writing a Client/Server program that relied on Tcp Communication.
the problems begin when one of the clients that already connected to the server decide to disconnect (shut down the program or because of an error).
the thing is that before he decide to disconnect his status is "Connected" (at the database)
and after that, when the client has disconnected, the socket keeps on being opened for at least 60sec because of that the client cannot reconnect to the server
(and because the server couldn't tell if the client has been disconnected or not so his status is still "Connected").
What can i do?
can i raise any event that will tell the server that one of the clients has disconnected himself?
pls, need help...
thanks...
|
|
|
|
|
I have still not seen any events that you can listen for when it comes to the socket class. What I do is to have a thread that is dedicated to doing nothing other than checking my array of socket connections. If it ever finds a connection that was closed from the remote end, it calls the necessary method. That's with C#.. I've done development in C++ with QTSockets, which do (God bless them) have events for socket disconnection.
|
|
|
|
|
Hi!
The TcpClient has timeout properties and a LingerState property that controls if and for how long the underlying socket is kept open.
Perhaps twiddling with these will help you closing the socket immediately.
Regards,
mav
|
|
|
|
|
I want to convert the CR & LN characters to and from their decimal values.
so I would have a text variable set to "\r" and/or "\n" and I would want to display these values to the user as "13" and/or "10". Allow the user to changes these to other decimal values and convert back to the text equivalent for searching in strings.
I have the convestion from decimal to character as follows, but what about the other way around ?
string Data = INI.GetINI("Settings","Seperator","/13/10");
string [] Seps = Data.Split('/');
string m_Sep=null;
foreach(string Sep in Seps)
{
if(Sep.Length==0)
continue;
m_Sep += (char)int.Parse(Sep);
}
|
|
|
|
|
Converting is easier than you think. Just use basic byte-char conversion:
char one = '\r';
byte val = (byte)one; //result is a 13
char two = (char)val; //result is '\r'
|
|
|
|
|
|
hi,
i want to recognize numbers:
0676xxxxxx
0664xxxxxx
must always begin with 0676 or 0664 .....
how can i test if the numer is between 6-9 digits?!?
<br />
Regex regex = new Regex(@"[(0664),(0676),(0699),(0650),(0660),(0688)][0-9]+?");<br />
Match m = regex.Match("213613213");<br />
<br />
if(m.Success)<br />
{ <br />
MessageBox.Show("True");<br />
}<br />
else<br />
{<br />
MessageBox.Show("False");<br />
}<br />
why the messagebox with true comes here?
cu
|
|
|
|
|
Your regular expression is equivalent to:
"[(),0456789][0-9]+?"
or
"[(),0456789]\d+?"
Use {6,9} to detect 6 to 9 occurances.
The Match method only checks if a match can be found inside the string. that means that the string "some text 0664123123 more text" will still be valit. If you want to match the entire string, you have to include the start of the string (^) and the end of the string ($).
This should be closer to what you want:
"^06(76|64)\d{6,9}$"
---
b { font-weight: normal; }
|
|
|
|
|
|
perfect now it works!
where can i read more about regex, in msdn ther's not very much!!
detect 6 to 9 occurances:
regex = new Regex(@"^06(76|64|50|60|68|69)\d{6,9}$");
is 6-9 here valid for the whole string
because of:
Match m = regex.Match("06761234567"); -> (m.Success) == true ....
cu
|
|
|
|
|
This is probably the best book about regex you can get:
http://www.amazon.com/exec/obidos/tg/detail/-/1565922573/104-5681665-2239906?v=glance
The {6,9} is only valid for the \d.
If you need it for the whole string you would need to do something like this: (regex\d{2,5}
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
I am trying to use a foreach to loop through a few datasets to update a table. With the code I have it is not working. I have checked both datasets with the quickwatch to make sure they are populated and they are. It runs through the code once, but on the second time through I get an error that the "SqlHelper.ExecuteScalar(Session["connect_string"].ToString(), System.Data.CommandType.Text, update).ToString();" statement, "Object not set to reference". I inserted a breakpoint and found that the Session variables are not changing in the update statement that I am creating. Any help would be appreciated.
foreach(DataTable mbTable in mb.Tables)
{
foreach(DataRow mbRow in mbTable.Rows)
{
Session["id"] = mbRow["m_id"].ToString();
Session["order"] = mbRow["m_ord_number"].ToString();
string dtdate = "SELECT stp_arrivaldate FROM stops WHERE ord_hdrnumber = '" + txtOrder.Text + "'";
DataSet dt = new DataSet();
dt = SqlHelper.ExecuteDataset(Session["connect_string"].ToString(),
System.Data.CommandType.Text, dtdate);
foreach(DataTable dtTable in dt.Tables)
{
foreach(DataRow dtRow in dtTable.Rows)
{
Session["dtdate"] = dtRow["stp_arrivaldate"].ToString();
string update = "UPDATE masterbrand_appt SET m_delivery_date = '" + Session["dtdate"].ToString() + "' WHERE m_id = '" + Session["id"].ToString() + "' AND m_ord_number = '" + Session["order"].ToString() + "'";
SqlHelper.ExecuteScalar(Session["connect_string"].ToString(),
System.Data.CommandType.Text, update).ToString();
}
}
}
}
Scott Moore
|
|
|
|
|
Why are you using session variables in this way? I can see nothing but trouble coming from that.
I suppose that you only get one record in the result from the select query? Why do you loop through all of the tables (a single one) and all of the rows (a single one)?
---
b { font-weight: normal; }
|
|
|
|
|
after a response I recieved through a C# yahoo group I completely agree. A man by the name of Brian showed me how to do it with SQL, which is how I wanted to do it, but could not figure it out.
Thanks for the reply.
Scott Moore
|
|
|
|
|
How do I put additional data in the request header array and how do I pick up that information on the server side?
I've created a custom sink and now I want to put data in the request header array to be able to pass additional information to the server side. But I don't know how to do it and I haven't found any descriptive example.
I thought that the ProcessMessage method on the client side was used to do it. But as I also has the IMessageSink.SyncProcessMessage in the class, it seems that the ProcessMessage method is never called.
I've seen examples (though I don't know if the work), where the request header array is assigned data on the client side, and the array is read on the server side. But those examples don't have the sink class inhereting from IMessageSink.
Any advice or example is helpful, thank you
|
|
|
|
|
The crucial thing here, is where the custom sink is intended to be placed. That is, before or after the formatter sink. If the custom sink is placed before the formatter, you work on the message. On the other hand, if the custom sink is placed after the formatter, you work on the stream.
My intentions was to have my custom sink "above" the formatter sink. And, if the first client sink shall be placed "above" the formatter sink, the IMessage interface needs to be implemented. This was why I had IMessageSink.SyncProcessMessage method in my class of course. In this situation you work on the message, and any manipulation to the message is done in the IMessageSink.SyncProcessMessage (or IMessageSink.AsyncProcessMessage) method. That's why the ProcessMessage method on the client side never was called.
This code snippet shows how to add some information to the message:
public IMessage SyncProcessMessage(IMessage msg)<br />
{<br />
msg.Properties.Add("Animal", "Fox");<br />
IMessage retMsg = ((IMessageSink) nextSink).SyncProcessMessage(msg);<br />
return retMsg;<br />
}
If you rather have your custom sink after the formatter sink, then it is the ProcessMessage method you're supposed to use. If so, the IMessageSink.SyncProcessMessage is not called. In this case you manipulate the array header to pass information to the server side, as follows:
public void ProcessMessage(System.Runtime.Remoting.Messaging.IMessage msg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)<br />
{<br />
requestHeaders["Animal"] = "Fox";<br />
<br />
nextSink.ProcessMessage(msg, requestHeaders, requestStream, out responseHeaders, out responseStream);<br />
}
In both cases, the ProcessMessage method on the server side is responsible to get the added information. But you use requestHeaders if you working on the stream, or the requestMsg if you're working on the message.
public ProcessMessage(IServerChannelSinkStack sinkStack, System.Runtime.Remoting.Messaging.IMessage requestMsg, ITransportHeaders requestHeaders, System.IO.Stream requestStream, out System.Runtime.Remoting.Messaging.IMessage responseMsg, <br />
out ITransportHeaders responseHeaders, out System.IO.Stream responseStream)<br />
{<br />
string msg = requestHeaders["Animal"] as string;
msg = requestMsg.Properties["Animal"] as string;
...<br />
...<br />
}<br />
|
|
|
|
|
Why in the world would Microsoft's new Studio 2005 give you something as fun as a transparency property for Forms, and not put that property in for all controls? I would really like to create an application that has transparent buttons, and when the user mouseOvers on the button, the buttons become clearer. I thought it would be a simple tasks, but I just could not get it done. I ended up faking it by having mini forms floating on top of my application, each with a transparency, but it looks buggy when you drag the application around. I want it docked like all other controls, but if you try to make your own custom control that extends from Form, it fails to dock because it considers Forms that the ultimate container so you can't but a Form into anything.
I do have some OpenGL experience, and could have a constantly running thread in my application that checks for mouse positions and draws GDI bitmaps to a drawing area with different levels of Alpha. However, I'm really hopping that I can do it more simply than that. Anyone have any ideas, or tried getting other controls to have transparency?
|
|
|
|
|
Hi,
I have an application which was developed in C# .NET , however this application uses some 3rd party controls which are available on the web for free,. during my setup process how should i pull those libraries at run time and install them on the user's desktop.
Any ideas would be great or any sample would be even nice.
I have build simple .MSI file using visual studio setup.
thanks in advance
Samar Aarkotti
|
|
|
|
|
Any dependant Dlls shoudl be automatically pickup up when you create the MSI install project by VS.NET. They will be included in the deployment package and written to the program directory by default.
Basically as long as you have a refernce to the controls in your project, the MSI should take care of it.
|
|
|
|
|
I know those things , but how do i get all the dll's at the runtime, so that MSI will pick those dlls from internet.
|
|
|
|