SlideShare a Scribd company logo
1 of 17
Multiplayer Java Stream-Socket
Game

By : KARIM BAIDAR
Objective
The objective is to create a Multiplayer game
where two distinct users can play that game
from two distinct computers.
How It is Operated

CLIENT

CLIENT

SERVER
PLAYER ‘O’

PLAYER ‘X’
Stream Sockets ?
• With stream sockets, a process establishes a
connection to another process
• Stream sockets are said to provide a
connection-oriented service
• The protocol used for transmission is the
popular TCP (Transmission Control Protocol)
Class Framework of Game
• Box-listener Class ( Listens to user click Events
on the surface board)

• Box Class (Implements each of the nine
square boxes on the surface board)
• Client Class (Maintains its own GUI version)
Class Framework Cont..
• Player Class(Enable the clients to play the
game independently)
• Server Class(The server maintains the
information about the Surface Board and
Clients)
Implementation of Server
• Via server we establish a connection using
ServerSocket()
• The server maintains the information about
the surface board so it can determine whether
a player’s move is a valid or invalid move.
Implementation of Server Cont..
• The game main logic is placed in Server class
• Server class is the Main Class
• Server waits for connection to connect two
clients
ServerSocket
• ServerSocket(Port Number , Clients);
• Implements a socket that servers can use to
listen for and accept connections to clients
• A ServerSocket object establishes the port
where a server waits for connections from
clients.
ServerSocket Cont..
• The server assigns X to the first client to
connect and O to second respectively
• The second argument to the ServerSocket
constructor specifies the number of clients
that can wait for a connection and be
processed by the server.
ServerSocket Cont..
• It performs some operation based on that
request

• Returns a result to the requester after
processing
Implementation of Client
• Sockets are initialized in Client as below
– Socket connection = new Socket( server Address, port );
– Gets the socket's input and output stream and opens
readers and writers on them.

• Player X and Player O used in the game are
both clients
Implementation of Client Cont..
• Each client applet maintains its own GUI version of
the surface board on which it displays the state of
the game
• The clients can place a mark only in an empty square
on the board
Implementation of Players
• Runs a thread to handle Multi Players
• Gets the socket's input and output stream and opens readers
and writers on them.

• Show messages from both Players X and O
perspectives.
ServerSocket Client Server
Why we used Sockets in the Game ?
• A socket is one endpoint of a two-way
communication link between two programs
running on the network
• Stream-based connections are managed with
Socket objects.
• A Socket object connects a client to a server
by specifying the server name and port
number when creating the Socket object..
Note
• Code and complete package is given.
• Contact me at karimbaidar@yahoo.com

More Related Content

What's hot

Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In JavaAnkur Agrawal
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using javaUC San Diego
 
Java networking programs socket based
Java networking programs socket basedJava networking programs socket based
Java networking programs socket basedMukesh Tekwani
 
Socket programming-tutorial-sk
Socket programming-tutorial-skSocket programming-tutorial-sk
Socket programming-tutorial-sksureshkarthick37
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket ProgrammingVipin Yadav
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal kotecha
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming TutorialJignesh Patel
 
Java- Datagram Socket class & Datagram Packet class
Java- Datagram Socket class  & Datagram Packet classJava- Datagram Socket class  & Datagram Packet class
Java- Datagram Socket class & Datagram Packet classRuchi Maurya
 

What's hot (20)

Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In Java
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using java
 
Java networking programs socket based
Java networking programs socket basedJava networking programs socket based
Java networking programs socket based
 
Java sockets
Java socketsJava sockets
Java sockets
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Tcp/ip server sockets
Tcp/ip server socketsTcp/ip server sockets
Tcp/ip server sockets
 
Sockets
SocketsSockets
Sockets
 
Socket programming-tutorial-sk
Socket programming-tutorial-skSocket programming-tutorial-sk
Socket programming-tutorial-sk
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket Programming
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Chap 1 Network Theory & Java Overview
Chap 1   Network Theory & Java OverviewChap 1   Network Theory & Java Overview
Chap 1 Network Theory & Java Overview
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Java- Datagram Socket class & Datagram Packet class
Java- Datagram Socket class  & Datagram Packet classJava- Datagram Socket class  & Datagram Packet class
Java- Datagram Socket class & Datagram Packet class
 
Java Networking
Java NetworkingJava Networking
Java Networking
 

Similar to Multiplayer Java Game

Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf euXie ChengChao
 
GamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming SystemGamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming SystemAcademia Sinica
 
Project Darkstar - Case Study at the 2008 Austin Game Developers Conference
Project Darkstar - Case Study at the 2008 Austin Game Developers ConferenceProject Darkstar - Case Study at the 2008 Austin Game Developers Conference
Project Darkstar - Case Study at the 2008 Austin Game Developers ConferenceChris Melissinos
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxRockyBhai46825
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.jsXie ChengChao
 
Multiplayer Networking Game
Multiplayer Networking GameMultiplayer Networking Game
Multiplayer Networking GameTanmay Krishna
 
Networking.pptx
Networking.pptxNetworking.pptx
Networking.pptxEsubesisay
 
Scrum alliance 2013-mmog
Scrum alliance 2013-mmogScrum alliance 2013-mmog
Scrum alliance 2013-mmogsajitv
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Server Based Gaming
Server Based GamingServer Based Gaming
Server Based Gamingmsw3725
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat applicationPiyush Rawat
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptxEliasPetros
 
Scalability & Big Data challenges in real time multiplayer games
Scalability & Big Data challenges in real time multiplayer gamesScalability & Big Data challenges in real time multiplayer games
Scalability & Big Data challenges in real time multiplayer gamesYan Cui
 
Php day2013 sports_statistics
Php day2013 sports_statisticsPhp day2013 sports_statistics
Php day2013 sports_statisticsTobias Josefsson
 
VM Console Enhancements
VM Console EnhancementsVM Console Enhancements
VM Console EnhancementsShapeBlue
 

Similar to Multiplayer Java Game (20)

Game server development in node.js in jsconf eu
Game server development in node.js in jsconf euGame server development in node.js in jsconf eu
Game server development in node.js in jsconf eu
 
GamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming SystemGamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming System
 
Project Darkstar - Case Study at the 2008 Austin Game Developers Conference
Project Darkstar - Case Study at the 2008 Austin Game Developers ConferenceProject Darkstar - Case Study at the 2008 Austin Game Developers Conference
Project Darkstar - Case Study at the 2008 Austin Game Developers Conference
 
Chapter 4--converted.pptx
Chapter 4--converted.pptxChapter 4--converted.pptx
Chapter 4--converted.pptx
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
 
Building fast,scalable game server in node.js
Building fast,scalable game server in node.jsBuilding fast,scalable game server in node.js
Building fast,scalable game server in node.js
 
Multiplayer Networking Game
Multiplayer Networking GameMultiplayer Networking Game
Multiplayer Networking Game
 
Sgin2013 scrum accomplished-mmog-sajitvasudevan
Sgin2013 scrum accomplished-mmog-sajitvasudevanSgin2013 scrum accomplished-mmog-sajitvasudevan
Sgin2013 scrum accomplished-mmog-sajitvasudevan
 
Networking.pptx
Networking.pptxNetworking.pptx
Networking.pptx
 
Scrum alliance 2013-mmog
Scrum alliance 2013-mmogScrum alliance 2013-mmog
Scrum alliance 2013-mmog
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Server Based Gaming
Server Based GamingServer Based Gaming
Server Based Gaming
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
Online casino
Online casinoOnline casino
Online casino
 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
 
Scalability & Big Data challenges in real time multiplayer games
Scalability & Big Data challenges in real time multiplayer gamesScalability & Big Data challenges in real time multiplayer games
Scalability & Big Data challenges in real time multiplayer games
 
Php day2013 sports_statistics
Php day2013 sports_statisticsPhp day2013 sports_statistics
Php day2013 sports_statistics
 
VM Console Enhancements
VM Console EnhancementsVM Console Enhancements
VM Console Enhancements
 
Java 1
Java 1Java 1
Java 1
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 

Multiplayer Java Game

  • 2. Objective The objective is to create a Multiplayer game where two distinct users can play that game from two distinct computers.
  • 3. How It is Operated CLIENT CLIENT SERVER PLAYER ‘O’ PLAYER ‘X’
  • 4. Stream Sockets ? • With stream sockets, a process establishes a connection to another process • Stream sockets are said to provide a connection-oriented service • The protocol used for transmission is the popular TCP (Transmission Control Protocol)
  • 5. Class Framework of Game • Box-listener Class ( Listens to user click Events on the surface board) • Box Class (Implements each of the nine square boxes on the surface board) • Client Class (Maintains its own GUI version)
  • 6. Class Framework Cont.. • Player Class(Enable the clients to play the game independently) • Server Class(The server maintains the information about the Surface Board and Clients)
  • 7. Implementation of Server • Via server we establish a connection using ServerSocket() • The server maintains the information about the surface board so it can determine whether a player’s move is a valid or invalid move.
  • 8. Implementation of Server Cont.. • The game main logic is placed in Server class • Server class is the Main Class • Server waits for connection to connect two clients
  • 9. ServerSocket • ServerSocket(Port Number , Clients); • Implements a socket that servers can use to listen for and accept connections to clients • A ServerSocket object establishes the port where a server waits for connections from clients.
  • 10. ServerSocket Cont.. • The server assigns X to the first client to connect and O to second respectively • The second argument to the ServerSocket constructor specifies the number of clients that can wait for a connection and be processed by the server.
  • 11. ServerSocket Cont.. • It performs some operation based on that request • Returns a result to the requester after processing
  • 12. Implementation of Client • Sockets are initialized in Client as below – Socket connection = new Socket( server Address, port ); – Gets the socket's input and output stream and opens readers and writers on them. • Player X and Player O used in the game are both clients
  • 13. Implementation of Client Cont.. • Each client applet maintains its own GUI version of the surface board on which it displays the state of the game • The clients can place a mark only in an empty square on the board
  • 14. Implementation of Players • Runs a thread to handle Multi Players • Gets the socket's input and output stream and opens readers and writers on them. • Show messages from both Players X and O perspectives.
  • 16. Why we used Sockets in the Game ? • A socket is one endpoint of a two-way communication link between two programs running on the network • Stream-based connections are managed with Socket objects. • A Socket object connects a client to a server by specifying the server name and port number when creating the Socket object..
  • 17. Note • Code and complete package is given. • Contact me at karimbaidar@yahoo.com