CSC 469 /569 Homework 6 .NET TCP Servers and Clients

Background Information on C#

Let us look at some background information before we begin. These are .NET and C# concepts that may prove useful to you as you are doing this assignment.

.NET Arrays

.NET arrays are similar to Java arrays. One slight difference is that the length of an array arr is capitalized: arr.Length.

Reading integers

In Java, to read integers and convert from their string form to binary, you use the Integer.parseInt(String s) method. In C#, you use int.Parse(String s). Google for examples if you need to.

You use the int.Parse(String s) when you know you are expecting to find an integer. If you have a string and you are not sure if it is an integer, you should use the int.TryParse(String s, out int num) method. This method will try to parse the string s into a number and store the number in the variable num. If the string is successfully parsed, the number is stored into num and the method returns true. Otherwise, the method returns false. Google for examples.

.NET Strings

It is sometimes useful to read in an entire line from a file or stream, and then split the line into an array of ``words." The .NET String.Split method does that for you. To split a string using blank spaces as delimiters, use the call:

 String inputLine = "The quick  brown fox jumps";
 String[] parts = inputLine.Split(new Char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

Note the option to remove empty entries. If you do not use this, a run of more than one blank space will be regarded as delimiting an empty string, and the array of words returned will contain entries that are empty strings.

.NET Dictionaries

.NET Dictionaries are the counterpart of maps on the Java platform. There based on the IDictionary interface, which you can learn about here. The important properties are Count, Keys and Values. The important methods are Add, Clear, Contains and ContainsKey.

It is instructive to look at the Remarks and Examples section on this page to see an example of creating and using a dictionary. This msdn page is long, but be sure to scroll all the way down and look at the examples of creating and using a dictionary.

Miscellaneous Information

The .NET framework has a StringBuilder class. All objects have a ToString() method: however, the ToString() method of collections and dictionary classes does not return a useful stringified view of the collection or dictionary, so do not rely on them.

The .NET framework has an enhanced for loop similar to that of Java. This loop works with arrays and collections, and dictionaries. You can find an example of the use of the enhanced for loop to print the mappings in a dictionary of the link to the msdn dictionary documentation given above.

The Assignment

Your assignment is to implement a multi-threaded map server and client following the protocol of Homework 2. Create Visual Studio Solution with two projects, a server and client. To submit, zip up the entire folder and submit by email. Visual Studio creates more than one folder for your project so make sure you are submitting the right folder. Before submitting, make sure the folder contains the source code. I will not be able to grade your submission if there is no source code.

Here is a sample screen shot of the client-side interaction:

Due Date

Saturday night at the end of Week 10.