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.

Sockets - Java Client & Python Server issues

Featured Replies

Hi guys,

I am using a java client to communicate to a python server (done as I know python well but my Java knowledge can be shaky) but I am encountering some issues.

The client code looks like this:

public String serverMuleRequest() {
    try {
        Socket socket = new Socket("localhost", 8080);
        DataOutputStream dataoutput = new DataOutputStream(socket.getOutputStream());
        DataInputStream datainput = new DataInputStream(socket.getInputStream());


        dataoutput.writeUTF("MULE");
        dataoutput.flush();
        String str = datainput.readUTF();//in.readLine();
        System.out.println("String: " + str);

        dataoutput.close();
        datainput.close();
        socket.close();
        return str;
    } catch (Exception e) {
        e.printStackTrace();
    }


    return "";
}


@Override

public void onStart() {
    log("Test");
    String strng = serverMuleRequest();
    log("Your string");
    log(strng);

}

The python code looks like this:

data = client_socket.recv(size)
                javaRequest = data.decode('utf-8')
                if 'q^' in data.decode('utf-8'):    
                    print('Received request for exit from: ' + str(
                        address[0]) + ':' + str(address[1]))
                    break

                if("MULE" in javaRequest):
                    looper = 1
                    print("Java request: " +javaRequest)
                    while(looper > 0):
                        try:
                            muleID, muleName, muleLoc = getMuleDetails(muleaccountpointer)
                            sendData = ("MULE_INFO:" +str(muleID) + ":" + str(muleName) + ":" + str(muleLoc) + ":")
                            client_socket.send(sendData.encode('utf-8'))

When I call the java code the following happens:

1. Test is printed to the console.

2. The socket connection is established and the python server sends over the correct message (tested with a python client).

3. After this the log("your string") and log(strng) will not actually run. I am unsure if something I have done in the socket function would cause this.

 

Does anyone have any ideas as I am a bit stuck!

Thanks!

First off, stop using port 8080 because that's already an established port for HTML. 

Second off, you only call it once... 

You need to do a loop on serverMuleRequest if you want it to keep writting. Like while (true) { method } - but you don't want to keep establishing a new socket, so you'll need to assign that somewhere else before the loop 

  • Author
9 hours ago, asdttt said:

First off, stop using port 8080 because that's already an established port for HTML. 

Second off, you only call it once... 

You need to do a loop on serverMuleRequest if you want it to keep writting. Like while (true) { method } - but you don't want to keep establishing a new socket, so you'll need to assign that somewhere else before the loop 

I fixed the issue it was due to me sending the response from python as Utf-8 encoded text and trying to receive in Java as utf-8 this messes up something somewhere. Sending as bytes then converting fixed it.

using port 8080 doesn’t matter I can use whatever port I like as it’s an internal application. In addition to this I only need to send the message once and get the reply from the server so there isn’t a need for the loop.

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.