Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4301860

Datagram Sockets produce IOException with "Connection refused" over Linux

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.2, 1.3.0
    • core-libs
    • x86
    • linux

         I have a customer *** running on Linux using our RC Linux JDK1.2.2
        with a testcase below that create datagram sockets to a host.

         The testcase works fine on our Solaris JDK, but fails with a
      IOException "Connection refused" on Linux using RC2 Linux JDK1.2.2.
      *** also noted that this bug appears in the RC3 JDK from Blackdown. This functionality is crucial to ***'s application.

      ***NOTE there are two test cases for the two problems seen here.
      The test below is rather confusing...Brad ****


      /*
      A basic Java class stub for a Win32 Console Application.
       */
      import java.net.*;
      import java.io.*;

      public class testudp {

      public testudp () {

      }

          static public void main(String args[]) {
              DatagramPacket rp;
              DatagramSocket s2host;
      // English:
      // own IP only with to generate the Socket one needs

              InetAddress ownIP; // eigene IP wird nur beim generieren des Socket ben÷tigt
              InetAddress toIP; // eigene IP wird nur beim generieren des Socket ben÷tigt
              byte [] recvbuf = new byte[1500]; // ReceiveBuffer
              int port;
              String srvIP;
              
              port = 7700;
              ownIP = null;
              srvIP = "10.10.10.174";
              //srvIP = "129.uuu.xxx.yyy"; // bongos
              // srvIP = "129.uuu.xxx.yyy"; // glimmer
              s2host = null;
              
              // socket wird ge÷ffnet
      // English:
      // Socket one opens
              try
              {
                  ownIP = InetAddress.getLocalHost();
                  s2host = new DatagramSocket(port, ownIP);
                  System.out.println("Socket opened " + s2host);
              }
              catch(Exception e)
              {
                  System.out.println(e.toString());
              }

              // Initialisierung des Timeouts f’r lesenden Zugriff auf den Socket
      // English:
      // Initialization of the Timeouts for reading access to the Socket
              try {
      // English:
      // if will not receive, after xx ms to abort
                  s2host.setSoTimeout(30); // falls nicht empfangen wird, nach xx ms abbrechen
                  System.out.println("Timeout set " + s2host);
              } catch(SocketException e) {
                  System.out.println("setSoTiemout failed " + e.toString());
              }

              // der Versuch etwas zu empfangen
      // English:
      // the attempt something to receive
              rp = new DatagramPacket(recvbuf, 1500);

              try {
                  s2host.receive(rp);
                  System.out.println("Receive OK " + s2host);
              }
              catch (InterruptedIOException e)
              {
                  System.out.println("receive ok but no data.");
              }
              catch(SocketException se)
              {
                  System.out.println("SocketException " + se.toString());
              }
              catch(IOException ie)
              {
                  System.out.println("IOException " + ie.toString());
              }

              // der versuch etwas zu senden
      // English:
      // the attempt something to transmit
              try
              {
                  // Wegen Absturz Linux Test
      // English:
      // Because of crash Linux Test
                  toIP = InetAddress.getByName(srvIP); // ZielAddresse, Targetaddress
                  
                  byte [] sendbuf = (new String("123456")).getBytes();
                  rp = new DatagramPacket(sendbuf, 6, toIP, 7700);
                  s2host.send(rp);
                  System.out.println("Send OK ?!?!" + s2host);
              }
              catch (IOException e)
              {
                  System.out.println("IOException beim Versenden " + e.toString());
              }

              // der Versuch etwas zu empfangen
      // English:
      // the attempt something to receive
              rp = new DatagramPacket(recvbuf, 1500);

              try {
                  s2host.receive(rp);
                  System.out.println("Receive OK " + s2host);
      String myinput= new String(rp.getData());
      System.out.println("rp.getData() ='" + myinput + "'");
              }
              catch (InterruptedIOException e)
              {
                  System.out.println("receive Interrupted Exception is ok.");
              }
              catch(SocketException se)
              {
                  System.out.println("Why ??? should work but : " + se.toString());
              }
              catch(IOException ie)
              {
                  System.out.println("IOException " + ie.toString());
              }

          }

      }

            michaelm Michael McMahon
            atongschsunw Albert Tong-schmidt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: