Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Server/Client only sends one line to eachother [SOLVED]

Featured Replies

I'm trying to build a mule script, and thus trying to build a server/client, where the client is the bot.

 

This is the client side of the code:

        while (true) {
                out.println(Protocol.REQUESTING_MULE);
                out.flush();
            System.out.println(in.readLine());

            if (in.readLine().startsWith("mule:")) {
                mule = in.readLine().substring(5);
                out.println(Protocol.GOT_MULE);
                out.flush();
                System.out.println(in.readLine());
               }
            if (in.readLine().equals(Protocol.REQUESTING_WORLD)) {
                out.println("World:123");
                out.flush();
                System.out.println(in.readLine());
            }
            if (in.readLine().equals(Protocol.REQUESTING_NAME)) {
                out.println("bot:bot");
                out.flush();
                System.out.println(in.readLine());
            }'
            Thread.sleep(2000);
        }

This is the server side of the code:

                while (true) {
                    System.out.println(in.readLine());
                    if (in.readLine().equals(Protocol.REQUESTING_MULE)); {
                        out.println("mule:mule");
                        out.flush();
                        System.out.println(in.readLine());
                    }
                    if (in.readLine().equals(Protocol.GOT_MULE)) {
                        out.println(Protocol.REQUESTING_WORLD);
                        out.flush();
                        System.out.println(in.readLine());
                    }
                    if (in.readLine().startsWith("World:")) {
                        world = in.readLine().substring(8);
                        out.println(Protocol.REQUESTING_NAME);
                        out.flush();
                        System.out.println(in.readLine());
                    }
                    if (in.readLine().startsWith("bot:")) {
                        bot = in.readLine().substring(4);
                        System.out.println(in.readLine());
                    }
                    System.out.println(bot);
                    System.out.println(world);

                    //Thread.sleep(2000);
                }

Console output, client side: image.png.af42a2ef94d2c09207999b585cbc48a0.png

Console output, server side: image.png.db4a586bff9875d4d34baefe5a01fe8b.png

 

The protocol:

public class Protocol {
    public static final String BREAK = "0";
    public static final String REQUESTING_MULE = "1";
    public static final String REQUESTING_NAME = "2";
    public static final String REQUESTING_WORLD = "3";
    public static final String GOT_MULE = "4";

}

 

I thought that because they were in a while(true) they would finish the conversation, but it seems they get stuck on the first message they are supposed to send each.
I've tried messing around with switch(in.println) and a lot of other stuff but I can't seem to get it to work properly. Any help would be greatly appreciated!

Edited by Nor3g

readLine is a blocking call and waits for input.

Your issue is that your making multiple reads when you should be just reading the value once at the time of your while loop.

msg = in.ReadLine();

if(msg == ..){
  
} else if (msg == ..){

} else {

}

You have to make your client and server very ping pong like:

If you read, then you must immediately write and vice versa. However, there should only be one read and it should be at the top.

 

You can look at this but it might be a bit confusing:

Also make your outputstream autoflash (set true in constructor)

Edited by dreameo

  • Author
8 hours ago, dreameo said:

readLine is a blocking call and waits for input.

Your issue is that your making multiple reads when you should be just reading the value once at the time of your while loop.


msg = in.ReadLine();

if(msg == ..){
  
} else if (msg == ..){

} else {

}

You have to make your client and server very ping pong like:

If you read, then you must immediately write and vice versa. However, there should only be one read and it should be at the top.

 

You can look at this but it might be a bit confusing:

Also make your outputstream autoflash (set true in constructor)

 

I don't know how to set outputstream to autoflush if that's what you meant. 

After implementing the other changes you suggested, and some other changes (like closing the socket), it eventually gets it right:

image.png.d01bf36f3fa86ba7f501b2535ec9c4ac.png

 

Even though It isn't breaking the program, I don't know why the client spams three consecutive messages to the server, or maybe it's the server spam printing one message three times to the console, but I'd rather have it a clean conversation. I'm going to work on this some more...

Thank you so much for helping me! :) Greatly appreciated!

 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.