The last class in the-client side of this applet is ScrvcrConnccticn, which encapsulates the communication with the server and our opponent. There arc several variables declared at the beginning of the class. The socket port Humber 10 attach to on the server. is 6564. CRLF is tile Internet constant string representing end-of-line. The I/O streams from and to the server arc in and out, respectively. The unique ID by which this connection is known on the server is stored in id -.The ID that we are connected to as an oppocnt is stored in toid. The Scrabblet applet we are connecting for is scrabblet.

ServerConnection( )
The ServerConnection constructor takes the name of an Internet site to attach to and attempts to open a socket to the right port on that host. If that succeeds, it wraps an InputStreamReader and a Buffered lceadcr around the input.and a  around the output. If the connection fails, an exception is thrown to the caller.

readline( )
The readline( ) method is merely a convenience function that converts the IOException from a readLine( ) into a simple null return.

setName( ) and delete( )
The setName( ) method tells the server to associate this name with us, and the delete( )  method, is used to remove us from any lists the server is keeping.

setTo( ) and end( ) .
The setTo( ) method binds the 10 of the opponent. Future send() calls will go to this

Share This