Our first assignment in PROG3060 was to develop a chat program in C# - a 'server' and a 'client' instance were to be created, where the client instance connects to the server instance. Once connected, messages could be sent from either instance by pressing the 'I' key - this would create an on-screen prompt for the user to write a text message, which would then be received by the other instance.
This program sounded like it would be more challenging to write than the line editor, but in fact Emily and I were able to finish it over the course of today's classes. As soon as someone says "network" with respect to programming I immediately freeze, assuming the problem will now be doubly complicated with the addition of TCP/IP protocols, sockets, and whatnot. In fact, nothing could be further from the truth.
The C# language has two class libraries - System.Net and System.Net.Sockets - that provide developers with a pre-made toolkit for creating network applications. The System.Net.Sockets class library includes the TcpListener and the TcpClient classes, which can be used to connect to servers and listen for incoming network transmissions. The NetworkStream class, also included in System.Net.Sockets, is used to hold the data to be transmitted, and has Read() and Write() methods to take data from/put data into the stream. System.Net gives developers access to the IPAddress class, which can be used to things like parse an IP address, tell the application to listen to or broadcast from all available ports, or use the loopback address.
Building the chat program was made easier with the help of several example programs we wrote in class. We were shown examples on 1) how to have an application listen for a keypress, 2) how to connect two console windows via a network connection, and 3) how to use command-line arguments. After being given the pieces of the puzzle, however, we were left to put it all together.
I must say I find this to be the best way to learn programming. After being given such clear examples, one can move forward with more confidence, knowing that the solution is reachable. I wish I'd been around more for Web Programming now - maybe ASP.NET wouldn't look at frightening as it does.
Thursday, January 22, 2009
Tuesday, January 20, 2009
PROG2020 Assignment 1. Line Editor
My two classes with Brian this semester are PROG2020 (Data Structures) and PROG3060 (Adv, OOP). We use C++ in our Data Structures class, while our code for Advanced OOP is written in C#. Although I like writing in C++, I must say that my initial exposure to C# has left me eager to write applications using it. It seems like a powerful and intuitive language.
First term was a bit of a challenge for me - I had a job that limited the amount of time I could put into my study, and it affected my comprehension of later C++ topics like polymorphism. The first two weeks have been a real boot camp for getting into coding shape, but I've enjoyed the quick pace. It's a lot easier to keep up with the pace of the class when I have time to set up and get ready. Showing up 30 minutes late isn't as conducive to making class time productive.
We've been given our first two assignments - for Data Structures, we've been asked to write a simple line editor that employs a structure called a linked list. A linked list is a data structure in which units of data are organized by means of pointers. The linked list is composed of nodes: each node is a data object that itself contains 1) some sort of data and 2) a pointer. This pointer carries as its value the address of the next node in the list; that next node also contains some sort of data and a pointer. That pointer, in turn, points to the next node, and so the chain continues, organizing the nodes into a linked list.
The line editor works by treating a text file as a set of written lines - each line is distinguished in the text file by ending with a carriage return. A linked list is used to store a file's text while it is being edited; each node in the linked list stores a string that corresponds to a line in the text file, as well as a pointer that points to the next node.
New lines can be inserted into the text by inserting a new node into the linked list, and lines can be deleted by deleting nodes. The text edits can be saved to the text file by iterating through the linked list and writing the string variables to the file.
I worked with Emily VanZeumeren on this assignment, and we gave ourselves the challenge of building a line editor that followed Brian's example as closely as possible. I wanted to treat the assignment as a request from a client, and that meant making the program work as requested. Emily and I talked over what we needed the program to do in order to achieve this - it forced us to think in detail about the user experience as described by the assignment's example, by the assignment's rubric, and by the verbal explanation in class.
We put the final touches on it today - code was formatted, variable names were standardized, etc. - and we made a few slight additions to the requested spec. We added one keyword - "help" - as way to print to screen all of the line editor's commands. We also have a two-line text output above the command prompt when the program launches. The additions are pretty slight and I think they offer some value, but part of me balked at even that deviation from the model. Overall, I'm really pleased with it - it functions as requested, and it closely mirrors the way the editor was outlined to us.
Our second program is going to be a chat client. I'll blog on it after we're done making it.
First term was a bit of a challenge for me - I had a job that limited the amount of time I could put into my study, and it affected my comprehension of later C++ topics like polymorphism. The first two weeks have been a real boot camp for getting into coding shape, but I've enjoyed the quick pace. It's a lot easier to keep up with the pace of the class when I have time to set up and get ready. Showing up 30 minutes late isn't as conducive to making class time productive.
We've been given our first two assignments - for Data Structures, we've been asked to write a simple line editor that employs a structure called a linked list. A linked list is a data structure in which units of data are organized by means of pointers. The linked list is composed of nodes: each node is a data object that itself contains 1) some sort of data and 2) a pointer. This pointer carries as its value the address of the next node in the list; that next node also contains some sort of data and a pointer. That pointer, in turn, points to the next node, and so the chain continues, organizing the nodes into a linked list.
The line editor works by treating a text file as a set of written lines - each line is distinguished in the text file by ending with a carriage return. A linked list is used to store a file's text while it is being edited; each node in the linked list stores a string that corresponds to a line in the text file, as well as a pointer that points to the next node.
New lines can be inserted into the text by inserting a new node into the linked list, and lines can be deleted by deleting nodes. The text edits can be saved to the text file by iterating through the linked list and writing the string variables to the file.
I worked with Emily VanZeumeren on this assignment, and we gave ourselves the challenge of building a line editor that followed Brian's example as closely as possible. I wanted to treat the assignment as a request from a client, and that meant making the program work as requested. Emily and I talked over what we needed the program to do in order to achieve this - it forced us to think in detail about the user experience as described by the assignment's example, by the assignment's rubric, and by the verbal explanation in class.
We put the final touches on it today - code was formatted, variable names were standardized, etc. - and we made a few slight additions to the requested spec. We added one keyword - "help" - as way to print to screen all of the line editor's commands. We also have a two-line text output above the command prompt when the program launches. The additions are pretty slight and I think they offer some value, but part of me balked at even that deviation from the model. Overall, I'm really pleased with it - it functions as requested, and it closely mirrors the way the editor was outlined to us.
Our second program is going to be a chat client. I'll blog on it after we're done making it.
Tuesday, January 13, 2009
Subscribe to:
Posts (Atom)