Java unable to call socket service
3922556 Apr 29, 2019 5:41 AMSo I have created a service on JDeveloper with socket adapter where a message is read from. I have followed the steps mentioned in the following link for that: https://shrikworld.blogspot.com/2014/11/demystifying-oracle-socket-adapter.html However the problem is that when i create the java class to test the service, i get an error.
I have been trying to figure out what the issue is but i cant find anything useful on this. Here is a description of the SocketAdapter in my weblogic console:
Host: localhost KeepAlive: true EnableSDP: false backlogQueue: 0 port: 12110 SSLEnable: false NeedClientAuthentication: false Timeout: 1000
Here is my java class:
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.net.Socket;
- public class Client {
- public static void main(String[] args) {
- try {
- Socket socket;
- final String HOST = "localhost";
- final int PORT = 12110;
- try {
- socket = new Socket(HOST, PORT);
- } catch (IOException ioe) {
- System.out.println(">>>");
- System.out.println(ioe.getMessage());
- System.out.println(">>>");
- throw ioe;
- }
- System.out.println("sending data: EmpDetails;");
- OutputStream os = socket.getOutputStream();
- byte[] b = "fn111111ln111111232007-01-01100\nfn211111ln211111232007-11-01200\nfn311111ln311111232007-12-01300".getBytes();
- for (int i = 0; i < b.length; i++) {
- os.write(b[i]);
- }
- os.flush();
- socket.shutdownOutput();
- System.out.println("receiving data");
- BufferedReader soc_in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- String successCode = soc_in.readLine();
- System.out.println("Success Code: " + successCode);
- socket.close();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- }
- }
and here is the error I get when I try running the code:
- java.net.ConnectException: Connection refused: connect
- at java.net.DualStackPlainSocketImpl.connect0(Native Method)
- at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
- at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
- at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
- at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
- at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
- at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
- at java.net.Socket.connect(Socket.java:589)
- at java.net.Socket.connect(Socket.java:538)
- at java.net.Socket.<init>(Socket.java:434)
- at java.net.Socket.<init>(Socket.java:211)
- at SocketAdapter.Client.main(Client.java:18)