C# And .dll’s

14 02 2008

I’ve been working on Fizzure A LOT recently. I made a FizzSrvLight that is not a distributed system like the regular one, which therefore allowed me to write one effectively in about 3 hours. On the way I decided to make a few of my own methods and then realized, hey these can be used in other projects too!

So I made a class library (.dll – Dynamically Linked Library ) with a few methods that have to do with TCP Data transmition. The most important of which is the Send method that I made. Now this is really only useful for the client. Anyway, heres the snippet:


public static void Send(TcpClient Client, String Command)
{
Console.WriteLine("Opening Server Stream");
NetworkStream n = Client.GetStream();
String send = Command;
String receive = null;
byte[] msg = System.Text.Encoding.ASCII.GetBytes(send);
n.Write(msg, 0, msg.Length);
Console.WriteLine("SENT: {0}", send);
}

this method is meant for console programs, but if you are using a GUI all you really need to do is delete the Console.WriteLines()’s in there and replace it with wherever you want the output.

Hope this is helpful to everyone!





Thoughts About Distributed Computing

20 01 2008

For me, distributed and parallel computing is one of the most interesting areas in computer science that I have found so far. I would really love to do work/research with it.

Distributed and Parallel Computing, at least from how I see it, seems to be the future of computers and processing power. Processors are starting to reach towards their physical limitations. So instead of making one processor even better, why not just use several, or even hundreds.

Slowly, I’m putting together my spare parts that I have at home into more computers to use. I got two more working in the last 2 days, both of which are semi decent machines. The main thing that I want to do with them is to try to make some of my own distributed applications that will be able to spread its processes out over several computers. Right now I have 3 computers that I want to use in my distributed system, the most powerful of which will be the main computer that is in charge of assigning the tasks. the other two, which are not as powerful, but still can handle plenty, will be sent instructions that will be processed and then they will send results back to the main server.

Now seeing as the 2 secondary nodes that will be in the system do not have the same specs, I have to make sure the server pays attention to the % of their resources that are being used when it goes to assign instructions. If the slower computer has been assigned less, but is using more of its resources, the next task that needs to be processed will be sent to the other computer.

Currently both of my secondary nodes are running Windows XP. This is fine I guess, but it seems like a large waste of system resources to have to run full windows. Though I realize that there is no way in hell that I can actually do this, I would love to write my own very basic OS just to handle being a secondary node in a distributed system. A node that when it turns on, simply connects to the central server, waits for its tasks, and then executes and sends back reports. No need for hogging resources with a gui or anything. All that is particularly necessary is enough to execute instructions and send/receive data over the network. But, when you actually think about it, that would take a very long time for me to figure out how to do. I don’t know the first thing about where an operating system starts really. Maybe I could use a linux kernel and just build off of that and get rid of things that aren’t really needed. I need to do a lot of research on this one.

This seems like it has the opportunity to be extremely efficient. Just a lightweight OS meant solely for being a secondary machine in a distributed  system would be so much faster than running anything i could create as a windows application. Unfortunately, I don’t know where to begin. Maybe I will set this one aside as a very long term project, slowly do research on it, and spend the bulk of my time on other projects are already have going like Fizzure. Haven’t worked on that one in a few days. Need to get back to it. I’ve been doing some little practice applications with sending and receiving data with the TcpClient and TcpListener class in C#. Now that I think I have a much better handle on how those work, it should be much easier to get over the hurdle I was stuck on with Fizzure.

Another goal I have is to make the Fizzure central server able to be split into nodes. Have different sections of all the XML data to be searched stored on different nodes. when a query comes in, the server sends a request to each node, each node searches the part of the data that it has stored and returns its results to the server, which than returns all of the results to the client. This seems more efficient than just having it all done by one computer, though because of network bandwidth, I don’t quite know if it would be in actuality.





Boo for inefficient applications!

9 01 2008

Everyone has used one. Mostly because everyone has used Internet Explorer. But everyone has gotten one of those programs that is just slow and a total resource hog. We all know and hate them. You feel even worse, though, when you realize you have created one yourself. I was pretty happy when I posted last because I had gotten a connection between the server and the client and everything was working pretty well.

Unfortunately, now I realize that, even though it does not use a whole lot of memory, the server uses 99% of my CPU. And I have a decent CPU as well. I mean, I know why it does it but i guess i have to figure out a way around it. Heres the code snippet that I’m pretty sure causes the problems:


while (true) {
if (server.Pending()) {
server.AcceptSocket();
Console.Out.WriteLine("Connection Accepted");
}
}

As you can see, the code just creates an infinite loop that checks for connections. Unfortunately this causes it to check about 2 billion times a second. which obviously…would use all of your processors resources. I’m trying to use a timer that checks every second, but I’m having trouble implementing it in a console application. Maybe I will change the server to a GUI application. Might be easier to do a lot of things. I guess I’ll have to ponder it for a while

EDIT: The problem has been fixed! Hooray! With a little bit of help from my good friend Windy, Just putting System.Threading.Thread.Sleep(1000); at the end brought the CPU usage down to 00% :] And it even brought down the memory usage a little! Hooray!





w00t – Great Success

9 01 2008

I know for most professional programmers and really anyone else in general it isn’t much of an accomplishment, but for me this is – I got the basic TCP connection working between the Fizzure client and server.

The server is just a lightweight console application. So far all it really does is accept connections. But for now I guess thats good enough. Today, I need to work on the XML usage of both the client and the server, and then the interaction with XML between the two. For efficiency I think I will do a lot of caching data. But I guess I need to figure out how to do that as well. I’m going to have to do a little more planning and deciding before I do too much programming.

Also though, I need to work on the GUI for the client.  I’m thinking about making it kind of skinnable. Or at least it will have different like color themes you can choose from. But eventually, I want it to be skinnable. People do seem to like that, it makes you feel like your program is just that much more personalizable.