|
learn magic. They make every thing come to you.
Yusuf
|
|
|
|
|
That actually made me snort/laugh!
Thank you.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Do you mean to retrieve the content of a web page without using/oprning a browser?
Regards,
Cybernate
|
|
|
|
|
No, I think Yusuf was right, I think he's referring to magic. The question is, is it White Magic or Black Magic?
|
|
|
|
|
if i am right. you want to open some web pages automatically when you run your application
for example you want to open following pages through your application just runnging your single application
1. yahoo mail
2. codeproject website
3. google
|
|
|
|
|
helu.... i am writing code for a server which listens on a port 1000; and i start the listener as a thread. but the problem is that when the client connections increase then the server is unable to handle the requests and errors n exceoptions occur.
i think the single thread is unable to handle that many conections. so is it possible to start multiple threads on the same port 1000;
thanks
|
|
|
|
|
No, you'd need more than 1 TCP socket on port 1000 (you can use a socket across multiple threads, but you shouldn't Listen() on multiple threads with the same socket) which is clearly illegal.
However, you could handle the request on an other thread if you're not already doing that.
|
|
|
|
|
thanks.. but "handle the request on an other thread" how can i do that is ti like statring a new thread when any new connection is made to the server
|
|
|
|
|
There are several ways, starting a new thread wouldn't be the best of them (too much overhead), but you could use the threadpool
Or, you could let the current thread handle the request but Before that, give the socket to an other thread to listen for more connections.
As long as the listening for more connections doesn't happen on the same thread as the handling of the existing connections doesn't happen on the same thread.
I'd probably loop the listener on its own thread and add the handling to the threadpool queue.
|
|
|
|
|
Hey Max,
Harold is dead on - you cannot run multiple listeners you MUST have only one listener, however you can then run separate threads to actually convert the socket into a connection...
I eventually used: http://www.codeproject.com/KB/IP/Generic_TCP_IP_server.aspx?fid=431256&select=2489157&fr=26#xx0xx[^]
The code is easy to understand and very powerful - i've added encryption/authentication as i went through the code - took a couple of days and ive been trying to get a solid TCP stack working with async methods for a few weeks!
However i did eventually used the async method for the listening socket, everything else is similar to the code in the link
On the 'new connection' i pass the async socket result to a connection event in a separate thread - as the code above looks at - minimising the time taken to process new socket before your listener can go back and wait for the next connection.
HAving said all that i haven't load tested it just yet
Good luck, C
|
|
|
|
|
Every time accept() returns successfully you will have a new client. You should start a new thread as pass the client socket to that thread so it can process indepently of the main thread.
incidentally the only thing your main thread should do is open the socket, accept new connections, dispatch new threads, and look for shutdown.
Move your action to worker threads and you will see a notable improvement in perfomance. However be advised you will need to take care of critical sections, and thread synchronization.
|
|
|
|
|
|
The AcceptSocket method will return a TcpSocket object moved to a different port so you can begin the accept cycle again. No code has to be written to change the port. You can then queue the Socket objects and parse them in a separate thread. Or you can use Asynchronous sockets. In no case will you need more than two threads to handle the connections.
Read the documentation here, http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.acceptsocket.aspx[^] and to verify that the ports are indeed automatically assigned for you run the command line method netstat.
|
|
|
|
|
In C#, using WMI has been great for access SI data. For reasons still unbeknownst to me, I cannot get a ManagementBaseObject instance (lets's call it mob) to properly invoke any of these function using InvokeMethod.
For example:
mof = "Rename";
name = "NEWNAME";
password = "adminpw";
user = "administrator";
object[] args = new args[3];
args[0] = name;
args[1] = password;
args[1] = user;
ManagementBaseObject mob = new ManagementBaseObject();
long retval = (long) mob.InvokeMethod(mof, name, password, user);
if (retval == 0)
Console.Writeline("Reboot PC for RENAME to take effect");
else
Console.Writeline("RENAME error {0}");
Everytime I get Invalid Method Parameter(s) message.
If anyone knows how to succcessfully call Rename, JoinDomainOrWorkgroup, etc from C#, please share the technique.
Thanks
|
|
|
|
|
There is a sample for InvokeMethod() here[^] and also here.[^] Frankly, I don't know how you managed to get to Invalid Method Parameter(s) with your code.
In January you said "Money in April" -
That was two years ago!
B. Python
|
|
|
|
|
The examples on MSDN are for Win32_Process and they work when I test. For some reason, Win32_ComputerSystem is behaving differently. I think there must a different way of calling the Win32_ComputerSystem functions. Here is the exact code that yields this result every time!
Exception caught!!!
System.Management: Invalid method Parameter(s)
public bool RenameComputer(string name, string password, string user)
{
bool ok = true;
string mofName = "Rename";
try
{
ManagementClass processClass = new ManagementClass("Win32_ComputerSystem");
object[] methodArgs = { name, password, user};
for (int i = 0; i < methodArgs.Length; ++i)
Console.WriteLine("methodArgs[{0}] = {1}", i, methodArgs[i]);
object retval = processClass.InvokeMethod(mofName, methodArgs);
Console.WriteLine("InvokeMethod Status {0}, Process ID {1}",
retval, methodArgs[3]);
}
catch (Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("{0}: {1}", e.Source, e.Message);
ok = false;
}
return (ok);
}
Has anyone been sucessful in calling Win32_ComputerSystem InvokeMethod() for Rename, or JoinDomainOrWorkgroup or UnjoinDomainOrWorkgroup. Help is greatly appreciated by me and anyone else dealing with this challenge.
|
|
|
|
|
Win32_ComputerSystem.Rename is an instance method so you first need to get the Win32_ComputerSystem instance to invoke it on:
ManagementClass computerSystemClass =
new ManagementClass("Win32_ComputerSystem");
object[] methodArgs = { name, password, user };
foreach (ManagementObject computerSystem in computerSystemClass.GetInstances())
{
object retval = computerSystem.InvokeMethod(mofName, methodArgs);
}
computerSystemClass.GetInstances() will return only one instance but you still need to use foreach. To avoid it, you could use the ManagementObject constructor that accepts the object path to get the instance:
ManagementObject computerSystem =
new ManagementObject("Win32_ComputerSystem.Name='SomeName'");
but you would have to get the computer name that you want to change first.
In January you said "Money in April" -
That was two years ago!
B. Python
|
|
|
|
|
|
Hi there!
I build C# application and then I add a setup project for the application within the solution. When I am installing the application, everything is going fine, I am starting the application, everything is going fine. When I want to insert some data in the database which is situated within the installation folder, I am getting this error:
a network-related or instance-specific error occured while establishing a connection to SQL server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL server is configured to allow remote connections. [provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified
Can someone explain me why I am getting this?? I will really appreciate. Thanks in advance, Laziale
|
|
|
|
|
what is the type of database you have in your installation folder?
The error you are getting is because you are trying to connect to an SQL Server instance. In which you need to setup SQL server and have the database part of an instance in that.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
the type of the database is Sql Server Express database. How I can solve that problem, can you give me some hint, I don't have any idea. Thanks in advance, Laziale
|
|
|
|
|
Im not hugely experienced with using it but as far as i known you will need to install SQL Server Express on the target machine, or on a server if its a network application. I think you can download the redistributable for SQL server express. you will then need to include that in your setup application. Then once that is set up you can create your database on it and use it as, i assume, you are using it for testing
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi!
The plan is this database to be used at the client environment. It is a management system, so they will need to pull and insert data in their local database. That's why I have doubts how to build this setup, I have SQL Server installed on my machine, I am installing the application, trying to insert some data and the error is occuring. That's what I want to know, why that error is occurring, since I have installed SQL Server on my machine. Thanks for your help, Laziale
|
|
|
|
|
does you application work when you test it before adding the setup?
Can you also post some code in relation to the database connection
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
yes, when I am running and debugging within VS, it works fine, I am inserting, selecting, deleting data from database. When I am running like standalone application, it gives me the error what I said in the first post.
Here is some code where I am selecting some data:
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Environment.CurrentDirectory + @"\App_Data\CMS.mdf;Integrated Security=True;User Instance=True;");
conn.Open();
string selectFamilyID = "SELECT Family_Id, Family_Name FROM Families WHERE Family_HouseHold = '" + fullName + "';";
SqlCommand selectCommand = conn.CreateCommand();
selectCommand.CommandText = selectFamilyID;
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = selectCommand;
DataSet myDataSet = new DataSet();
string dataTableName = "Families";
adapter.Fill(myDataSet, dataTableName);
int familyID = 0;
DataTable table = myDataSet.Tables["Families"];
foreach (DataRow row in table.Rows)
{
familyID = Convert.ToInt32(row["Family_Id"]);
secondName = Convert.ToString(row["Family_Name"]);
}
|
|
|
|