tailieunhanh - peer-topeer Networks phần 4

Xác định vị trí hai khối sau đây trong file trong thư mục conf. Invoker debug 0 2 Invoker / servlet / * 2. Hủy bỏ dòng đầu tiên và dòng cuối cùng của hai khối trên (tức là). 3. Lưu tập tin . Bạn có thể tắt chức năng này bằng cách thêm dòng đầu tiên và cuối cùng để các khối. 4. Tạo các lớp học con đường | 70 7. Java Network Programming need more flexibility in communication we need to use more complex methods. Socket communication is one of them. It is similar to a phone conversation. The communication process with phones consists of the following steps Dial the number. Wait for the other side to pick up the phone. Talk to each other once the connection is established. Hang up the phone. It has the following characteristics The connection must be established before the communication. Connection is maintained even if the line is idle. For example your friend asks a question in the phone conservation. You need to think for several seconds before you can answer so there is an idle period. The connection is closed only after the communication process is completed. Client Side Program Socket The following client program sends a request to establish connection with the server. It despatches a simple message How are you to the server and waits for the answer. It then displays the answer on the screen. The program is presented in Fig. . First try block. The connection is established with the following lines. The first line sends a request for connection to the server. The second and third lines initialise the PrintStream object for output and BufferReader object for input . powerSocket new Socket IP 3333 out new PrintStream in new BufferedReader new InputStreamReader The syntax for defining the socket is Socket nameOfSocket nameOfSocket new Socket IP 3333 The syntax for defining the output object is PrintStream nameOfOutputObject null nameOfOutputObject new PrintStream The syntax for defining the input object BufferedReader nameOfInputObject null nameOfInputObject new BufferedReader new InputStreamReader import . import . public class socketclient public static void main String args throws IOException String IP PrintStream out null .

TỪ KHÓA LIÊN QUAN