Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411507 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 26, 2024, 06:08:08 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Networking notworking [java] *FIXED* *WAS NEVER RLY BROKEN*
Pages: [1]
Print
Author Topic: Networking notworking [java] *FIXED* *WAS NEVER RLY BROKEN*  (Read 1265 times)
tanner bananer
Level 1
*


aspiring train conductor


View Profile WWW
« on: April 11, 2015, 07:28:09 AM »



this is my first time doing networking and im using java and i dont know why my players are only showing up on one screen,  the other two are supposed to look like the first one. I'm holing the x, y, height, and a name for each player in an object and i have a reciever class holding an arraylist of the player objects and i dunno.
« Last Edit: April 14, 2015, 11:30:28 AM by μηκοοι » Logged

kamac
Level 10
*****


Notoriously edits his posts


View Profile
« Reply #1 on: April 11, 2015, 07:56:48 AM »

One word: DEBUG

There's no way we could know how to fix such a specific issue without seeing any code.
Logged

tanner bananer
Level 1
*


aspiring train conductor


View Profile WWW
« Reply #2 on: April 11, 2015, 08:06:22 AM »

One word: DEBUG

There's no way we could know how to fix such a specific issue without seeing any code.

figured. i dunno what i need to show tho, like all my code?

i'll give ya this, it's my receiver

Code:
Thread activity = new Thread(this);
    MulticastSocket so;
    ArrayList<Pig> players;

    Receiver(MulticastSocket sock, ArrayList<Pig> players)
    {
        so = sock;
        this.players = players;
        activity.start();
    }

public void run() {
        byte[] data = new byte[1024];
        while (true)
            try {
                DatagramPacket packet = new DatagramPacket(data, data.length);
                so.receive(packet);
                String mess = new String(data, 0, packet.getLength());
                Scanner get = new Scanner(mess);
                String name = get.next();
                Double x = get.nextDouble();
                Double y = get.nextDouble();
                Double h = get.nextDouble();
                boolean here = false;
                for(int i = 0;i<players.size();i++)
                {
                    if(name.equals(players.get(i).name))
                    {
                        here = true;
                        players.get(i).x=x;
                        players.get(i).y=y;
                        players.get(i).h=h;
                    }
                }
                if(!here)
                {
                    players.add(new Pig(x,y,h,name));
                }
            }
            catch (IOException e) {break;}
    }

and this is in my initialize method

Code:
        try{iadr = InetAddress.getLocalHost();}catch(UnknownHostException e){}
        try{so = new MulticastSocket(port);}catch(IOException e){}
        try{so.joinGroup(iadr);}catch(IOException e){}
        new Receiver(so,players);

and Pig is the name of the player class
« Last Edit: April 11, 2015, 08:16:25 AM by μηκοοι » Logged

oahda
Level 10
*****



View Profile
« Reply #3 on: April 11, 2015, 08:09:17 AM »

Maybe the code that's supposed to be drawing the characters.
Logged

tanner bananer
Level 1
*


aspiring train conductor


View Profile WWW
« Reply #4 on: April 11, 2015, 08:10:49 AM »

Maybe the code that's supposed to be drawing the characters.

the draw function is in the player class and it's working as much as that method would show

this is proly what u want

Code:
for(int j = 0;j<players.size();j++)
                {
                    if((int)(players.get(j).y/size) == i)players.get(j).draw(g,x,y,h,spaces[(int)(players.get(j).x/size)][(int)(players.get(j).y/size)].h);
                }
Logged

Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #5 on: April 11, 2015, 09:24:01 AM »

There is no way for us to see the problem without the full picture. As well keep in mind multiple lines are your friend. It's easier to see a problem with your code when it's not all stuffed into a single line.
Logged
tanner bananer
Level 1
*


aspiring train conductor


View Profile WWW
« Reply #6 on: April 11, 2015, 10:38:34 AM »

There is no way for us to see the problem without the full picture. As well keep in mind multiple lines are your friend. It's easier to see a problem with your code when it's not all stuffed into a single line.

well that long draw function's perfectly functional rn. i guess i'll try n find it out myself.
Logged

tanner bananer
Level 1
*


aspiring train conductor


View Profile WWW
« Reply #7 on: April 14, 2015, 11:28:10 AM »

I'm a dingus the problem was they were all on my ip so it only sent me the data once  Lips Sealed
Logged

Sik
Level 10
*****


View Profile WWW
« Reply #8 on: April 14, 2015, 08:29:41 PM »

So, it was identifying them by the IP address, not by the socket? (this can bring issues in the future, e.g. two computers under the same router may appear as the same IP address to outsiders)
Logged
tanner bananer
Level 1
*


aspiring train conductor


View Profile WWW
« Reply #9 on: April 15, 2015, 05:22:04 AM »

So, it was identifying them by the IP address, not by the socket? (this can bring issues in the future, e.g. two computers under the same router may appear as the same IP address to outsiders)

nah I'm using sockets and identifying by username which is proly inefficient but eh we tested it and had it functioning in my comp sci class n we were all in the same room on the same router
Logged

Cheezmeister
Level 3
***



View Profile
« Reply #10 on: April 15, 2015, 01:04:27 PM »

I would just like to say that I love this thread's title and also μηκοοι's handle.
Logged

෴Me෴ @chzmstr | www.luchenlabs.com ቒMadeቓ RA | Nextris | Chromathud   ᙍMakingᙌCheezus II (Devlog)
Sik
Level 10
*****


View Profile WWW
« Reply #11 on: April 15, 2015, 01:26:17 PM »

we tested it and had it functioning in my comp sci class n we were all in the same room on the same router

Within the same router you will all see your addresses before they get changed by the router. I meant situations like two siblings in the same house (thereby the same router) playing with other people (who will see their external addresses since they aren't under the same network).

Identifying by username is not that slow if you hash the strings (not even something complex, just quickly adding all the bytes will do the job). Then you can easily rule out when an username isn't the one you want by doing a quick integer comparison before checking the full string =P (hash clashes can happen, but you will still avoid most of the string checks, which is the idea)
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic