Wrap-Up

Answers to Self Review Exercises

23.1

a) False. UDP is a connectionless protocol, and TCP is a connection-oriented protocol. b) False. Packets can be lost, arrive out of order or even be duplicated. c) True. d) False. TcpListener's AcceptSocket method may be called as often as necessaryeach call will accept a new connection. e) False. A TcpListener can listen for connections at only one port at a time. f) False. A UdpClient can send information to any port represented by an IPEndPoint. g) TRue. h) True. i) False. When an object is marshaled by reference, the client application accesses the original remote object on the server, not a local copy. j) False. A Singleton remote class instantiates one remote object to service all clients.

23.2

a) System.Net, System.Net.Sockets. b) UdpClient. c) IPAddress. d) stream, datagram. e) Transmission Control Protocol. f) TcpListener. g) TcpClient. h) NetworkStream. i) Navigate. j) Serializable, ISerializable. k) transparent proxy.

Exercises

23.3

Use a socket connection to allow a client to specify a text file's name and have the server send the contents of the file or indicate that the file does not exist.

23.4

Modify Exercise 23.3 to allow the client to modify the contents of the file and send the file back to the server for storage. The user can edit the file in a TextBox, then click an Update file on server button to send the file back to the server.

23.5

Multithreaded servers are quite popular today, especially because of the increasing use of multiprocessing servers. Modify the simple server application presented in Section 23.6 to be a multithreaded server. Then use several client applications and have each of them connect to the server simultaneously. Use a HashTable (namespace System.Collections) to store the client threads. HashTable provides several properties and methods of use in this exercise. Property Keys returns an ICollection of keys currently found in the HashTable. Each key can then be used in the HashTable's indexer to retrieve the corresponding value. Method Add places its argumentsa key and a valueinto the HashTable. Method Remove deletes its argumentthe keyfrom the HashTable.

23.6

Create a client/server application for the game of Hangman, using socket connections. The server should randomly pick a word or phrase from a file. After connecting, the client should be allowed to begin guessing. If a client guesses incorrectly five times, the game is over. Display the original phrase or word on the server. Display dashes (for letters that have not been guessed yet) and the letters that have been guessed in the word or phrase on the client.

23.7

Modify the previous exercise to be a connectionless game using datagrams.

23.8

(Checkers Game) In the text, we presented a Tic-Tac-Toe program controlled by a multithreaded server. Develop a checkers program modeled after the Tic-Tac-Toe program. The two users should alternate making moves. Your program should mediate the players' moves, determining whose turn it is and allowing only valid moves. The players themselves will determine when the game is over.

23.9

(Networked Morse Code) Perhaps the most famous of all coding schemes is the Morse code, developed by Samuel Morse in the 1830s for use with the telegraph system. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit and a few special characters (such as period, comma, colon and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Other representations of dots and dashes are used with light-oriented systems and signal-flag systems.

Separation between words is indicated by a space, or quite simply, the absence of a dot or dash. In a sound-oriented system, a space is indicated by a short period of time during which no sound is transmitted. The international version of the Morse code appears in Fig. 23.14.

Figure 23.14. English letters of the alphabet and decimal digits as expressed in international Morse code.

Character

Code

A

.-

B

-...

C

-.-.

D

-..

E

.

F

..-.

G

--.

H

....

I

..

J

.---

K

-.-

L

.-..

M

--

N

-.

O

---

P

.--.

Q

--.-

R

.-.

S

...

T

-

U

..-

V

...-

W

.--

X

-..-

Y

-.--

Z

--..

Digits

 

1

.----

2

..---

3

...--

4

....-

5

.....

6

-....

7

--...

8

---..

9

----.

0

-----

 

Write a client/server application in which two clients can send Morse code messages to each other through a multithreaded server application. The client application should allow the user to type English-language phrases in a TextBox. When the user sends the message, the client application encodes the text in Morse code and sends the coded message through the server to the other client. Use one blank between each Morse-coded letter and three blanks between each Morsecoded word. When messages are received, they should be decoded and displayed as normal characters and as Morse code. The client should have one TextBox for typing and one TextBox for displaying the other client's messages.

23.10

Write a bulletin board application that uses .NET remoting. Create a remote object that will allow the client application to list all available bulletins, retrieve the text of any bulletin and post a new bulletin. Each bulletin should be stored in a .txt file in the server's directory. Refer to Chapter 18, Files and Streams.

23.11

Write a quiz application that uses .NET remoting. Store one quiz question in a text file on the server machine. Allow the client to retrieve the question from the server and send an answer back to the server. You may wish to store records of who answered the quiz question correctly so the server operator can keep score.

Preface

Index

    Introduction to Computers, the Internet and Visual C#

    Introduction to the Visual C# 2005 Express Edition IDE

    Introduction to C# Applications

    Introduction to Classes and Objects

    Control Statements: Part 1

    Control Statements: Part 2

    Methods: A Deeper Look

    Arrays

    Classes and Objects: A Deeper Look

    Object-Oriented Programming: Inheritance

    Polymorphism, Interfaces & Operator Overloading

    Exception Handling

    Graphical User Interface Concepts: Part 1

    Graphical User Interface Concepts: Part 2

    Multithreading

    Strings, Characters and Regular Expressions

    Graphics and Multimedia

    Files and Streams

    Extensible Markup Language (XML)

    Database, SQL and ADO.NET

    ASP.NET 2.0, Web Forms and Web Controls

    Web Services

    Networking: Streams-Based Sockets and Datagrams

    Searching and Sorting

    Data Structures

    Generics

    Collections

    Appendix A. Operator Precedence Chart

    Appendix B. Number Systems

    Appendix C. Using the Visual Studio 2005 Debugger

    Appendix D. ASCII Character Set

    Appendix E. Unicode®

    Appendix F. Introduction to XHTML: Part 1

    Appendix G. Introduction to XHTML: Part 2

    Appendix H. HTML/XHTML Special Characters

    Appendix I. HTML/XHTML Colors

    Appendix J. ATM Case Study Code

    Appendix K. UML 2: Additional Diagram Types

    Appendix L. Simple Types

    Index



    Visual C# How to Program
    Visual C# 2005 How to Program (2nd Edition)
    ISBN: 0131525239
    EAN: 2147483647
    Year: 2004
    Pages: 600

    Similar book on Amazon

    Flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net