<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Why can I not submit data via sockets in the java SDK? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Why-can-I-not-submit-data-via-sockets-in-the-java-SDK/m-p/538192#M9659</link>
    <description>&lt;P&gt;Below I have a setup which is submitting an event to splunk. I would like to not recreate a connection and stream several events at a time. What can I do to achieve this? I attempted to use a socket below, but it always errors out with `&amp;lt;msg type="ERROR"&amp;gt;Read Timeout&amp;lt;/msg&amp;gt;`.&lt;/P&gt;&lt;LI-CODE lang="java"&gt;public class Main
{
  static final ObjectMapper mapper = new ObjectMapper();

  public static void main(String[] args) throws Exception
  {
      Map&amp;lt;String,Object&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
      {
        map.put("host", System.getenv("SPLUNKHOST"));
        map.put("username", System.getenv("USER"));
        map.put("password", System.getenv("PASSWORD"));
      }
      Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
      final Service srv = Service.connect(map);

      working(srv);
      broken(srv);
  }

  static void working(Service srv) throws Exception {
    final Receiver receiver = srv.getReceiver();
    String str = mapper.writeValueAsString(data("rec_http"));
    receiver.log("api_analytics", str);
  }

  static void broken(Service srv) throws Exception {
    final Index index = srv.getIndexes().get("api_analytics");
    final Socket sock = index.attach();

    String str = mapper.writeValueAsString(data("sock"));
    final OutputStream out = sock.getOutputStream();
    final InputStream in = sock.getInputStream();
    out.write(str.getBytes());
    String r = new String(in.readAllBytes());
    System.out.println(r);
    sock.close();
  }

  static Object data(String src) {
    Map&amp;lt;Object,Object&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
    map.put("index","api_analytics");
    map.put("source",src);
    return map;
  }
}&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 01 Feb 2021 22:54:32 GMT</pubDate>
    <dc:creator>tjones</dc:creator>
    <dc:date>2021-02-01T22:54:32Z</dc:date>
    <item>
      <title>Why can I not submit data via sockets in the java SDK?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-can-I-not-submit-data-via-sockets-in-the-java-SDK/m-p/538192#M9659</link>
      <description>&lt;P&gt;Below I have a setup which is submitting an event to splunk. I would like to not recreate a connection and stream several events at a time. What can I do to achieve this? I attempted to use a socket below, but it always errors out with `&amp;lt;msg type="ERROR"&amp;gt;Read Timeout&amp;lt;/msg&amp;gt;`.&lt;/P&gt;&lt;LI-CODE lang="java"&gt;public class Main
{
  static final ObjectMapper mapper = new ObjectMapper();

  public static void main(String[] args) throws Exception
  {
      Map&amp;lt;String,Object&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
      {
        map.put("host", System.getenv("SPLUNKHOST"));
        map.put("username", System.getenv("USER"));
        map.put("password", System.getenv("PASSWORD"));
      }
      Service.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
      final Service srv = Service.connect(map);

      working(srv);
      broken(srv);
  }

  static void working(Service srv) throws Exception {
    final Receiver receiver = srv.getReceiver();
    String str = mapper.writeValueAsString(data("rec_http"));
    receiver.log("api_analytics", str);
  }

  static void broken(Service srv) throws Exception {
    final Index index = srv.getIndexes().get("api_analytics");
    final Socket sock = index.attach();

    String str = mapper.writeValueAsString(data("sock"));
    final OutputStream out = sock.getOutputStream();
    final InputStream in = sock.getInputStream();
    out.write(str.getBytes());
    String r = new String(in.readAllBytes());
    System.out.println(r);
    sock.close();
  }

  static Object data(String src) {
    Map&amp;lt;Object,Object&amp;gt; map = new HashMap&amp;lt;&amp;gt;();
    map.put("index","api_analytics");
    map.put("source",src);
    return map;
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 01 Feb 2021 22:54:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-can-I-not-submit-data-via-sockets-in-the-java-SDK/m-p/538192#M9659</guid>
      <dc:creator>tjones</dc:creator>
      <dc:date>2021-02-01T22:54:32Z</dc:date>
    </item>
  </channel>
</rss>

