Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

handling client side and server side in online game (java)

Posted on 2000-05-05
11
Medium Priority
?
297 Views
Last Modified: 2012-05-04
actually how is the way to handle client and server side when we are making online game.
0
Comment
Question by:eddyhalim
  • 6
  • 5
11 Comments
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2782480
From: Sasha_Mapa
 Date: Sunday, April 30 2000 - 07:32PM CST  
First, I would like to know what exactly are you offering the points for, what is the specific question/s you want answered or problem/s solved?

I am a member at playsite and I can tell you several things:

A. It is so far from being perfect that it can't see "perfect" with a telescope. Why do I say that? It is horribly, unbeliavably slow. The applet itself is HUGE, it takes about 10 mins to download it. They lack a lot of the features any standard game server has, check out www.chessclub.com for a real chess server with an amazing graphical interface and so many more features. I am sure you can find a site 10 times better for any of the games on playsite, but I only play chess so I know about chess.

B. First, the bigger and more difficult part of writing a site like that is the server side rather than the client. As a server you must make sure that the server is compatible with all the interfaces you have ever released as there is no guarantee people will upgrade. Just think of all the things the server must implement, here are just some examples:
1. Move legality checking, this is definitely the server's job, because otherwise I can log on to the server with telnet and send "bad" moves.
2. Timestamping - Lag must not affect the course of a timed game, so a timestamping algorithm must be implemented in order to compensate for lag.
3. Keeping track of all the games along with their times in real time.
4. An easily extendible server interface that would allow adding new features with ease.
5. If you want a good server, it must be able to recieve unparsed data from the client, because it is always possible to connect to the server with telnet and it should be possible to play from there too.

C. The client is pretty easy to write, and I know, I wrote a client for www.chessclub.com in Java. It was so easy thanks to the very well designed server-client protocol defined by chessclub's server programmer. All that a client must do is sit tight and wait for orders from the server. The server sends its orders using DataGrams, these are small batches of information that the client needs to know. For example, "The white player moved e4" would be sent with something like (just made that up, but I hope you get the idea) "^K56 4143" where ^K means a start of a datagram, 56 is the code of the datagram and 4143 is the move e2e4.

I hope this made it clear that this is not an easy task and such a site could take several years to write, even for a skilled team of developers.

If you wish to see an actual working server, go to http://www.freechess.org/ log on and ask someone to tell you where to find the source for their server. It is a free chess server and their code is freely available on the net. For a powerful client that goes with that server ask for the sources of WinBoard.



Writing a chat is much easier...
You have to implement the graphical interface that would allow the user to input text and display text. All the client should take about 15K-20K as a java applet. That would take me several days to write because it is fairly easy, the basic features of a chat are implemented by displaying a text field and a text area. The server side is also fairly easy to implement. All that it does is recieve text from the client, add the user's handle to the message (maybe check for "bad" words and substitute them with *) and send it to all the clients currently connected.

Hope this helps you... What are you intending to do anyway and why are you asking such a question so that I can help you more specifically.


Accepted Answer  
From: Sasha_Mapa
 Date: Monday, May 01 2000 - 04:15AM CST  
I don't know how to play pokemon, we've only heard about it over here in Israel. Hmm Tamagotchi... Seems pretty easy... Only problem I can anticipate is that if you get a lot of users and use a 'bad' (slow comp, little memory, bad OS) server, you will run out of threads you can open to keep the state of the tamagotchi. I experimented a bit with opening threads, Windows 98 seems to die (and I mean DIE, no bluescreen, no reboot, no nothing) after about 1500 threads. On Solaris, the process of opening threads got slower after 8K and then I got tired. Didn't try NT. If you are not planning on many users, there shouldn't be a problem.
So like what do you want? Steps to create such a thing?

I am assuming you want the tamagotchi to 'persist', i.e. if the user logs off and then comes back, the tamagotchi is still there and in the meanwhile might have grown up, died etc.

Server-side:
1. Define the 'animal' and the 'things' it can do. The animal is the class, the things it can do are its methods.
2. Define an interface with the client. The client should be able to send requests to modify the state of the tamagotchi and the server should be able to inform the user of a change in the state of the tamagotchi, either a change requested by the user, or a change caused by the 'natural' flow of events.
3. You need to keep a thread for each tamagotchi and in that thread you will usually sleep, and once in a while, wake up, change the state of the tamagotchi according to its current state and go back to sleep.
4. The tamagotchi class should implement adding/removing a tamagotchi change listener (I am assuming you are familiar with that term), when a user connects, you add a listener to the user's tamagotchi, when the user disconnects, you remove that listener. The listener is responsible to inform the user of the change that occured in the tamagotchi by sending it one of the datagrams you defined in (1).
5. You will need to keep a Hashtable of tamagotchi objects with a user name as the key. When the user logs on, you find his tamagotchi, add a listener to it and do what is stated in (4).
6. When the user logs out, you remove the listener.

The client:
1. Also implement a tamagotchi object. You can't use the same implementation, as they will have essentially different implementations. For example, the server's tamagotchi has no idea how it looks, it is an 'abstract' tamagotchi, it just has states in which it can be, the client tamagotchi knows what to do when reacting to change of states sent to it by the server. Define an interface (or an abstract class) for the Tamagotchi and implement it with an initial test implementation. The methods that need to be in the interface are essentially draw(Graphics), various setState methods, like setSleep(boolean), feed(Food) etc. and various getState methods like isAsleep(), lastFed() etc.
2. The initial implementation can just display textual messages instead of drawing a pretty looking animal. It can also in the beginning return constant values in the getState methods. After you see that it works more or less, implement those methods for real one by one keeping it in working shape after each change.
3. The setState methods will send requests of change of state to the server and do nothing more. When the data is sent back by the server, another thread will be set up to modify the state of the tamagotchi on the client.
4. The getState() methods will return current states of the tamagotchi. This is needed because for different animals different changes of state are not always available. For example you can't feed an animal when its asleep, so there's no point in asking the server to do that. Instead on such a request you should display the user with some error message. Btw, the server should also perform those checks, but it will probably have less of those because it will allow more possibilities for an animal. For example you may decide to come up with some alien animal that can eat and sleep at the same time, so the server should allow it, but feeding a dead animal or killing a not yet born one is not possible for any animal.
5. Finally, define the draw(Graphics) method to display the user some pretty animal and not text messages.
6. Write the graphic user interface that will allow the user to execute commands on the tamagotchi (feed, put to sleep etc.) and add the tamagotchi to be a part of it.


The final step: DEBUG. Make sure you have as few bugs as possible. Put the applet on the net, give your friends the address and specifically ask them to 'torture' the program, do things a normal user will not usually do. After you will fix the 1001 and bugs your friends find out, you can happily write the documentation for your project (at least a general one...what each class and portion of code is responsible for) and go public :-)


If you are skilled, an initial version should take you a couple of weeks and in 2 months it should be finished and ready to go.

Another idea for a project is something I did just for practice when I started learning Java - a checkers playing applet. Check out mine at http://members.xoom.com/_XMCM/Alexander123.1/Home.html, remember I was just starting to learn Java when I wrote it, hehe.

Good luck, Sasha.
0
 

Author Comment

by:eddyhalim
ID: 2784955
actually sasha has answer techpage's answer
which is the friend of mine.
now i need to know :
consider the client server chatting:
the server will listening and receive the info.the client just connect to the listening and send the data through the ipaddress and port number.

now how about the chatting between client & client which connect through the server.
how is it work?

the second, actually in our java program do we need to write a special source code to handle the server and client side.
0
 

Author Comment

by:eddyhalim
ID: 2784956
Adjusted points from 100 to 200
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Ravindra76
ID: 2784968

Java Server :-

      It will contain a Vector or Hashtable of Client Threads.

      IT watis in infinite loop to listen for connections.
      
      When a request comes, it creates a socekt and put it in Vector or Hashtable.

      It will create a seperate thread to Handle further IO with that socket connection.

Java Client :-

      It is also a thread. It will connect to server for a specified port.

      It will send and receive message from server.

Two clients chatting:-

      The client will tell server to send a message.

      The server will boradcast the message to other clients by looking the clients
      in its Vector or Hashtable.

This is the typical way the chat will work.

Never two clients interact with each other directly.

Server is the common interface and it will broad cast the message.

I hope U undestand

:)

      
0
 

Author Comment

by:eddyhalim
ID: 2786881
but if the server broadcast it. Isn't it become a multi chating(not private chat).now how about private chat.
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2791299
Server will maintain Private Users Vector of Vector seperately.

The client1 will send a request to client2 to join in his group.

IF client2 accepts it, server will add client2 the client1 private group.

Whenever the client1 request to pass a message to client2,(or others in his group),
the server will broadcast message to remaining clients in his group.

You have to differentiate the message as public or private from client only.
0
 

Author Comment

by:eddyhalim
ID: 2795403
by the way how is it work in:(logically)
Server maintain Private Users Vector of Vector seperately.

0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2797708
SOrry.

Maintain hashtbales


Vector users = new Vector() ;

User user = new User(userKey); // userKey is unique user
Vector userGroup  = new Vector();
userGroup.addElement("XXX");
userGroup.addElement("XXX");
userGroup.addElement("XXX");

HashTable privateGroup= new HashTable();
privateGroup.addElement(userKey,userGroup);

/*
      users is vector of all users ( Public or Private )
      UserGroup will contain the  users  who are privat to him.
      privatGroup will maintain the key value pair of  username and userGroup
      From the client , if it is public message, U will tell to server the type of message
      is public.

      Then server will broadcast message to all the members of user group.

      From the client, if it is private message, U have to tell private user name and
      type of message as private.

      Then server will find corresponding userGroup for the user given by client and
      get thegroup from hash table and broadcast message

*/
0
 
LVL 7

Accepted Solution

by:
Ravindra76 earned 600 total points
ID: 2797710
SOrry.

Maintain hashtbales


Vector users = new Vector() ;

User user = new User(userKey); // userKey is unique user
Vector userGroup  = new Vector();
userGroup.addElement("XXX");
userGroup.addElement("XXX");
userGroup.addElement("XXX");

HashTable privateGroup= new HashTable();
privateGroup.addElement(userKey,userGroup);

/*
      users is vector of all users ( Public or Private )
      UserGroup will contain the  users  who are privat to him.
      privatGroup will maintain the key value pair of  username and userGroup
      From the client , if it is public message, U will tell to server the type of message
      is public.

      Then server will broadcast message to all the members of user group.

      From the client, if it is private message, U have to tell private user name and
      type of message as private.

      Then server will find corresponding userGroup for the user given by client and
      get thegroup from hash table and broadcast message

*/
0
 
LVL 7

Expert Comment

by:Ravindra76
ID: 2797716
SOrry.

Maintain hashtbales


Vector users = new Vector() ;

User user = new User(userKey); // userKey is unique user
Vector userGroup  = new Vector();
userGroup.addElement("XXX");
userGroup.addElement("XXX");
userGroup.addElement("XXX");

HashTable privateGroup= new HashTable();
privateGroup.addElement(userKey,userGroup);

/*
      users is vector of all users ( Public or Private )
      UserGroup will contain the  users  who are privat to him.
      privatGroup will maintain the key value pair of  username and userGroup
      From the client , if it is public message, U will tell to server the type of message
      is public.

      Then server will broadcast message to all the members of user group.

      From the client, if it is private message, U have to tell private user name and
      type of message as private.

      Then server will find corresponding userGroup for the user given by client and
      get thegroup from hash table and broadcast message

*/
0
 

Author Comment

by:eddyhalim
ID: 2803404
thanks a lot.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question