so iv been programming for awhile and im trying for the first time to make a multiplayer game. The main problem im having right now is updating the data of multiple clients on the server side simultaneously.
heres the concept behind my code:
Membuat Aplikasi Client Server Dengan Bahasa Pemrograman Java → Membuat Program MultiClient Chatting Client-Server Menggunakan Bahasa Pemrograman Java Berbasis Grafis Posted on 2014/07/03 by andikabaelah28. Cara Membuat Aplikasi Chatting Java dan MySQL di Windows 7 Menggunakan Protokol TCP/IP - Pada tulisann ini kita akan belajar tentang apa itu pemrograman jaringan. Dimulai dari kata PEMROGRAMAN dan JARINGAN.Pemrograman adalah suatu kegiatan membuat kode program dan selanjutnya program tersebut dijalankan.
- Client establishes connection with server->
- client sends messages to the server based on what key is pressed on the client side->
- server updates itself 60 times a second based off of what key is currently being pressed by the client
my main problem is with step 3, and my problem is a syntax error in my main thread:
error message is:The method calculatePos() is undefined for the type ServerSocket.
what I tried to do was to make an array of ServerSockets, and update them all 60 times a second. each socket is its own thread of the server class.
Iv listed the entire server program below:
This is the main class for the server. This class listens for client connections and makes a new thread each time a client connects.
server thread class:
updater thread class:
1 Answer
Your error comes from Server. You are storing same server socket over and over again. And you do not store your ServerThread
object
ServerSocket accept() - http://download.java.net/jdk7/archive/b123/docs/api/java/net/ServerSocket.html#accept()
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made. A new Socket s is created and, if there is a security manager, the security manager's checkAccept method is called with s.getInetAddress().getHostAddress() and s.getPort() as its arguments to ensure the operation is allowed. This could result in a SecurityException.
Returns: the new Socket
So what you should do to handle clients is to save this ServerThread object. And if you want relevant returning socket too. !
Not the answer you're looking for? Browse other questions tagged javamultithreadingsockets or ask your own question.
Welcome to my tutorial where Voidx and I will be expanding on my previous article to provide more clarity into the logic of the code.
My code can be found here -> http://pastebin.com/2nYicFPM
*****************************
Index:
$->Keyword
!->Start of code
^->End of code
*****************************
Keywords:
continue-> This key work is used to indicate that if the program does catch any errors to ignore them.
static->This key word is used to indicate that the variable is related to a type not a particular instance of the variable.
![Dengan Dengan](http://4.bp.blogspot.com/-S1qdg2AdSQA/VN7OPh_1x9I/AAAAAAAAAGM/M7tJWAMcmyA/s1600/7.3.png)
private->This indicates that the particular variable can only be accessed by class or method which created it.
************DISCLAIMER************
Voidx nor me is responsible for anything done with the backdoor.*
******************************