Tải bản đầy đủ (.pptx) (49 trang)

Thuyết trình chủ đề game oẳn tù tì

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (910.45 KB, 49 trang )

Oẳn Tù Tì Game Report

Game

GVHD

:

Group menbers:

TS Nguyễn Đức Thái
Mai Văn Tinh
Võ Thanh Biết
Đỗ Luật Khoa
Nguyễn Phúc Ánh


1. Overview Game

6.Demo

2.Model

What next...
5. Game activity
3. Socket Client-Server

4. Extension
2



1. Overview Game


1. Problems
Who win

Network

Player 1

Player 2


2.Model
Client/Server model

Client 1

Request
Response

Request

Response
Request
Client 2

Response

Server



2.Model
Features of Client/Server Architecture
• Multi-user support
 Server can process requests from multiple clients simultaneously

• Transparency of location
 Clients need not be aware of physical location of server

• Mix and match of platforms
 Client and server may have heterogeneous platforms

• Scalability
 Provides scope for scalability and ease of maintenance


3. Socket Client-Server
 Socket
 Multicast
 Thread


3. Socket Client-Server
- Socket:
Sockets are network communication link end-points between two
applications (i.e., server and client).

Source : Advanced Network Programming Principles and Tecniques



3. Socket Client-Server
- Socket:
Sockets are network communication link end-points between two
applications (i.e., server and client).

Figure The
java.net package

- - There are two type of Sockets:
- - Transport layer socket: TCP and UDP
- - Application layer Socket: HTTP, SMTP
. Image from: />

3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (TCP).
 TCP Socket :Server Side
ServerSocket servSock = new ServerSocket(portno);
/*1024 <= portno <= 65535*/

Socket sock = servSock.accept();
/*sock is a socket object.*/

Source : Advanced Network Programming Principles and Tecniques


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (TCP).

 TCP Socket :Server Side

BufferedReader in = new BufferedReader(
new InputStreamReader(sock.getInputStream()));
PrintWriter out = new PrintWriter(sock.getOutputStream(), true);

Send and receive data.
out.println("Waiting...");
String msg = in.readLine();
Close;

Source : Advanced Network Programming Principles and Tecniques


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (TCP).

 TCP Socket: Client side

Create a TCP client socket and establish a connection to the server.
InetAddress srvIPAddr;
int srvPortNo = 1234;
Socket sock = new Socket(srvIPAddr.getLocalHost(), srvPortNo);

Source : Advanced Network Programming Principles and Tecniques


3. Socket Client-Server
important parameters:

IP address, port number, and communication protocol (TCP).

 TCP Socket: Client side
Set input and output streams.
BufferedReader in = new BufferedReader
(new InputStreamReader(sock.getInputStream()));
PrintWriter out =new PrintWriter(sock.getOutputStream(), true);
Send and receive data.
out.println("");
String msgIn = in.readLine();
Close the connection

Source : Advanced Network Programming Principles and Tecniques


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (TCP).
 TCP Socket: Client side

The packets are guaranteed to arrive
(if lost, retransmission occurs)
and are received in order at the destination

Source : Advanced Network Programming Principles and Tecniques


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (TCP).


/>

3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (UDP).

 UDP Socket:
 When using UDP sockets the connection between the client and
the server is not maintained throughout the communication
session

 There are no guarantees that the packets arrive in order at the
destination or that the packets arrive at the destination at all.

Source : Advanced Network Programming Principles and Tecniques


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (UDP).

 UDP Socket: Server side

Create a datagram socket object.
DatagramSocket dgramSocket = new DatagramSocket(portno);
/*1024 <= portno <= 65535*/
Create a buffer to store the incoming datagrams:
byte[] buffer = new byte[256];
/*-128 <= byte value <= 127*/

Create a datagram packet object for incoming datagrams:
DatagramPacket inPkt =
new DatagramPacket(buffer, buffer.length);


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (UDP).

 UDP Socket: Server side
Accept an incoming datagram:
dgramSocket.receive(inPkt);

Get sender’s address and port number from the datagram:
InetAddress cliAddress = inPkt.getAddress();
int cliPort = inPkt.getPort();
Retrieve the data from the buffer:
String msgIn = new String(inPkt.getData(), 0, inPkt.getLength());


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (UDP).

 UDP Socket: Server side

msgOut = ("Message out ");
DatagramPacket outPkt =
new DatagramPacket(msgOut.getBytes(),msgOut.length(),
cliAddress,cliPort);

Send the response datagram:
dgramSocket.send(outPkt);
Close the datagram socket:
dgramSocket.close();


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (TCP or UDP).

 UDP Socket: Client side
Create a datagram socket object:
DatagramSocket dgramSocket = new DatagramSocket();

BufferedReader userEntry = new BufferedReader(new
InputStreamReader(System.in));
String msg = userEntry.readLine();
DatagramPacket outPkt = new DatagramPacket(msg.getBytes(),
msg.length(), host, portno);


3. Socket Client-Server
important parameters:
IP address, port number, and communication protocol (UDP).

 UDP Socket: Client side
Send the response datagram:
dgramSocket.send(outPkt);
Accept an incoming datagram:
dgramSocket.receive(inPkt);

Retrieve the data from the buffer:
String msgIn = new String(inPkt.getData(), 0, inPkt.getLength());

Close the datagram socket:
dgramSocket.close();


3. Socket Client-Server

22


3. Socket Client-Server
 Multicast Introduction
Multi-casting involves one-to-many communications between a sender
and a set of receivers

/>

3. Socket Client-Server
 Multicast Introduction
-These receivers must belong to a multicast group
- All class D IP addresses are multicast addresses and range from
224.0.0.0 to 235.255.255.255

/>

3. Socket Client-Server
 Multicast introduction
The sender has to send data to the multicast group IP address. The

receivers need to join the multicast group in order to receive data from
the transmitting sender

/>

×