0

I have recently made a 2d game in java and need help with making a network protocol that works. I am currently using DataOutputStream and DataInputStream with Sockets and ServerSocket. The Joining is working but the communication between the client and the server is not working. The way I want to have it work and the way i have it set up is so the server does the running and updating and the client receives the position info and data and renders the game and sends back control inputs for the player on the server.

Process:

server: starts
client: starts and sends username to the server 
server: replies with a UID witch is used to identify the 
      client and is assigned to the player that is the client 
client: sends inputs to server and server receives them 
      updates the player and sends the data and position info 
      to the client
client: reconstructs the data to a player and renders it
(repeat last 2 steps)

This is what I have currently for the reading and writing functions writing method]

What I am looking for is suggestions of things I could do or Ideas to try. Thanks

Grim
  • 1,938
  • 10
  • 56
  • 123
Grefreino
  • 11
  • 2
  • Just a suggestion: you can create a class for thing like stats and player which allows you to use ObjectInputStream and ObjectOutputStream to send and receive data between client and server. This can make you code much cleaner and easy access to data. – printfmyname Aug 25 '16 at 22:28
  • 1
    Next time, post your code as text, not as an image. Arguments are passed by value in Java. So, whatever you assign to the arguments in the method, the caller won't know, and the caller's variable won't change. This is basic stuff that you should master long before making a game with networking. – JB Nizet Aug 25 '16 at 22:50

0 Answers0