2

I have a scenario with three devices: Android-Smartphone, Linux-Laptop (Linux mint) and a Sony a7R camera.

My goal is to talk to the camera using the laptop and Sony's http-SDK via WiFi (Cam opens an hotspot). The SDK comes with the code for an Android sample app. It first sends an SSDP packet whereupon the camera answers with an UDP packet, so far so good. Using the same java-code on linux, the packet is send, too, but the answer is never received. The desired UDP packet, however, appears on the laptop (verified using wireshark).

Question: Where is the packet? How can I make the java app receive the packet on linux?

This is the code (based on the Sony's sample app). It is almost identical both for Android and vanilla Java.

/*
 * Copyright 2014 Sony Corporation
 */

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class JavaSsdpTest {
  public static void main(String[] args) {
    search();
  }

  private static final String TAG = "MainActivity";
  private static final int SSDP_RECEIVE_TIMEOUT = 10000; // msec
  private static final int PACKET_BUFFER_SIZE = 2048;
  private static final int SSDP_PORT = 1900;
  private static final int SSDP_MX = 1;
  private static final String SSDP_ADDR = "239.255.255.250";
  private static final String SSDP_ST = "urn:schemas-sony-com:service:ScalarWebAPI:1";

  public static class Log {
    static void i(final String tag, final String msg) {
      System.out.println(tag + ": " + msg);
    }
  }

  public static synchronized void search() {
    final String ssdpRequest =
        "M-SEARCH * HTTP/1.1\r\n" + String.format("HOST: %s:%d\r\n", SSDP_ADDR, SSDP_PORT)
            + String.format("MAN: \"ssdp:discover\"\r\n")
            + String.format("MX: %d\r\n", SSDP_MX)
            + String.format("ST: %s\r\n", SSDP_ST) + "\r\n";
    final byte[] sendData = ssdpRequest.getBytes();

    new Thread() {
      @Override
      public void run() {
        // Send Datagram packets
        DatagramSocket socket = null;
        try {
          socket = new DatagramSocket();
          InetSocketAddress iAddress = new InetSocketAddress(SSDP_ADDR, SSDP_PORT);
          DatagramPacket packet = new DatagramPacket(sendData, sendData.length, iAddress);
          socket.send(packet);
          Log.i(TAG, "Sent packages");
        } catch (Exception e) {
          Log.i(TAG, "send: Something went wrong:");
          System.exit(1);
        }
        // Receive reply packets
        byte[] array = new byte[PACKET_BUFFER_SIZE];
        try {
          DatagramPacket receivePacket = new DatagramPacket(array, array.length);
          socket.setSoTimeout(SSDP_RECEIVE_TIMEOUT);
          socket.receive(receivePacket);
          Log.i(TAG, "Received package: " + receivePacket.getData().length);
          System.exit(0);
        } catch (Exception e) {
          Log.i(TAG, "recv: something went wrong");
          System.exit(1);
        }
      }
    }.start();

  }
}
  • Have you checked if you have a firewall? This would be a reason to see the packet at the network level but not at the application one. – Patrick Mevzek Mar 16 '18 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.