حجم فایل : 156.6 KB
نوع فایل : پاور پوینت
تعداد اسلاید ها : 30
بنام خدا الگوريتم كار برنامه سمت مشتري امكانات زبان جاوا Applet اپلت دو راه اجراي يك اپلت محدوديتهاي اپلت Network Request Result a client, a server, and network Client Server Client machine Server machine Elements of C-S Computing java.net Used to manage:
URL streams
Client/server sockets
Datagrams 19 Part III - Networking ServerSocket(1234) Socket(“128.250.25.158”, 1234) Output/write stream Input/read stream Server_name: “manjira.cs.mu.oz.au” Server side Socket Operations 1. Open Server Socket:
ServerSocket server;
DataOutputStream os;
DataInputStream is;
server = new ServerSocket( PORT );
2. Wait for Client Request:
Socket client = server.accept();
3. Create I/O streams for communicating to clients
is = new DataInputStream( client.getInputStream() );
os = new DataOutputStream( client.getOutputStream() );
4. Perform communication with client
Receiive from client: String line = is.readLine();
Send to client: os.writeBytes("Hello ");
5. Close sockets: client.close();
For multithreade server:
while(true) {
i. wait for client requests (step 2 above)
ii. create a thread with “client” socket as parameter (the thread creates streams (as in step (3) and does communication as stated in (4). Remove thread once service is provided.
} Client side Socket Operations 1. Get connection to server:
client = new Socket( server, port_id );
2. Create I/O streams for communicating to clients
is = new DataInputStream( client.getInputStream() );
os = new DataOutputStream( client.getOutputStream() );
3. Perform communication with client
Receiive from client: String line = is.readLine();
Send to client: os.writeBytes("Hello ");
4. Close sockets: client.close();
22 A simple server (simplified code) import java.net.*;
import java.io.*;
public class ASimpleServer {
public static void main(String args[]) {
// Register service on port 1234
ServerSocket s = new ServerSocket(1234);
Socket s1=s.accept(); // Wait and accept a connection
// Get a communication stream associated with the socket
OutputStream s1out = s1.getOutputStream();
DataOutputStream dos = new DataOutputStream (s1out);
// Send a string!
dos.writeUTF(“Hi there”);
// Close the connection, but not the server...
مبلغ واقعی 18,824 تومان 20% تخفیف مبلغ قابل پرداخت 15,059 تومان