Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CS480 Socket Programming Lab1 Overview Work individually or in a group of no mor

ID: 3600326 • Letter: C

Question

CS480 Socket Programming Lab1           

Overview

Work individually or in a group of no more than three members to build two simple client/server applications using C# sockets. The first one is a simple echo/chat service. The second one is a simple file transfer service.

Procedure and Details (30 points): Compile, Test, And Extend Example Echo Application

_______ Obtain a copy of the code for the echo client, and the echo server on the course web site.

______ Create two folders first, one for server and one for client. For example, c:server and c:client

Build EchoServer and EchoClient in Visual Studio 2010/2012:

           

Now your server and client applications should be in their folders, suppose server is in “c:serverserverdebug” and client application is in folder “c:clientclientdebug”.

_______ To test the server, you will need a unique application number greater than 1025, such as 2000x, where x is 0 to 9.

            Open a DOS window, change directory with “cd” command to the directory where server application is, suppose “c:serverserverdebug”. Run server application with “server 2000x”.

            Open another DOS window, change directory with “cd” command to the directory where client application is, suppose “c:clientclientdebug”. Run client application with “client localhost 2000x”. Or you can use “ipconfig” command to get your computer IP address, suppose it is 192.168.0.1, then run client application with “client 192.168.0.1 2000x”.

            After sending some echo messages, you can quit your client application by enter “exit”.

           

            Now you can shut down your server application.

_______ Test the client and server by running the server on one computer and the client on another. You may need to use “ipconfig” command to get the server IP address for the client.

_______ Modify the server to keep a log file containing all data the server echoes. Save your server application with name serverX, and client with name clientX, where X is the number you picked before.

_______ every group submits your serverX.cs, clientX.cs, serverX.exe and clientX.exe, to the drop box before due date.

Write a chat application (35 points):

_______ Modify the echo client and the echo server so they both can chat with each other, in this case, it is a chat application. During the chat, they each require the user to enter a “name” (an arbitrary string). Prepend the name followed by a greater-than sign to each line of text before sending the text across the network.

_______ If both sides like to record the chatting, log file would certainly serve this purpose. Modify the code so that each side has its own log file to record all of the chatting information.   

_______every group submits your chatsX.cs, chatcX.cs, chatsX.exe and chatcX.exe, to the drop box before due date.

Write a simple file transfer application (35 points):

_______ Modify the echo client and the echo server so the client can send a file to the server, in this case, it is a simple file transfer application. Proper user interaction should be provided.

_______ You may consider to use FileStream(from System.IO), its read() and write() methods. You may also consider using our discussions about sending and receiving variable length messages (check socket slides).  

_______every group submits your ftpsX.cs, ftpcX.cs, ftpsX.exe and ftpcX.exe, to the drop box before due date.

Explanation / Answer

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Programs { public class Student { public string First { get; set; } public string Last { get; set; } public int ID { get; set; } public List Marks; public ContactInfo GetContactInfo(Programs pg, int id) { ContactInfo allinfo = (from ci in pg.contactList where ci.ID == id select ci) .FirstOrDefault(); return allinfo; } public override string ToString() { return First + "" + Last + " : " + ID; } } public class ContactInfo { public int ID { get; set; } public string Email { get; set; } public string Phone { get; set; } public override string ToString() { return Email + "," + Phone; } } public class ScoreInfo { public double Average { get; set; } public int ID { get; set; } } List students = new List() { new Student {First="Tom", Last=".S", ID=1, Marks= new List() {97, 92, 81, 60}}, new Student {First="Jerry", Last=".M", ID=2, Marks= new List() {75, 84, 91, 39}}, new Student {First="Bob", Last=".P", ID=3, Marks= new List() {88, 94, 65, 91}}, new Student {First="Mark", Last=".G", ID=4, Marks= new List() {97, 89, 85, 82}}, }; List contactList = new List() { new ContactInfo {ID=111, Email="Tom@abc.com", Phone="9328298765"}, new ContactInfo {ID=112, Email="Jerry123@aaa.com", Phone="9876543201"}, new ContactInfo {ID=113, Email="Bobstar@aaa.com", Phone="9087467653"}, new ContactInfo {ID=114, Email="Markantony@qqq.com", Phone="9870098761"} }; static void Main(string[] args) { Programs pg = new Programs(); IEnumerable studentQuery1 = from student in pg.students where student.ID > 1 select student; Console.WriteLine("Query : Select range_variable"); Console.WriteLine("Name : ID"); foreach (Student s in studentQuery1) { Console.WriteLine(s.ToString()); } Console.ReadLine(); } }