This site requires JavaScript, please enable it in your browser!
Greenfoot back

Discussions

You need to login to take part
Rss

Current Discussions

Game/maniac

User Info server, How I did it.

By Game/maniac, with no replies.
First I decided I need a separate id for every user using the scenario. To do this I checked if the user had a score of 0, and if the user did, the user was given an id 1 integer larger than the highest score on the scenario (The id is the name I have given for the score). Next I distinguished the server from the client by putting an "s" at the beginning of string 0, and after the "s" was the name of the server. When the accept command has been called, the server looks at all the users who have been on the scenario, and checks if string 0 contains the servers name and id, if it does the server adds the users id to string 1. This is counted as a connection between the client and server. When the receive packet command is called, the server looks through all the users connected and adds whatever is in string 2 to the packet array. when the send packet command is called the server uses string 3 and 4 to store the packet, waiting for the client to read it. ------------------------------------------------------------------------------------------------------- Like in the server class, the user is given a unique id. When the join server command is called the client checks if the server exists, then the name of the server and id of the server is added to the end of string 0. When the send packet command is called, the client adds the packet to string 2. when the receive packet command is called, the client creates a packet class containing string 3 and 4 of the server. ------------------------------------------------------------------------------------------------------- The packet is just a class that contains an id and string. ------------------------------------------------------------------------------------------------------- Have any questions, just ask. Link to scenario: UserInfo server