Example usage for java.net SocketException printStackTrace

List of usage examples for java.net SocketException printStackTrace

Introduction

In this page you can find the example usage for java.net SocketException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.socsimnet.server.Server.java

@Override
public void run() {
    try {//  w  ww .  ja v  a  2s .  c om
        serverSocket = new ServerSocket(this.port);
        Socket client;
        System.out.println("Server is listening port " + this.port + "...");
        while (!this.stop) {
            try {
                client = serverSocket.accept();
            } catch (SocketException e) {
                break;
            }
            System.out.println("Client accepted " + client.toString() + " hash:" + client.hashCode());
            this.cDB.put(client.hashCode(), client);
            new ClientHandler(this, client).start();
        }
        System.out.println("Server shutting down...");
        printCloseMessage();
        serverSocket.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.esa.nest.util.ftpUtils.java

public FTPError retrieveFile(final String remotePath, final File localFile, final Long fileSize)
        throws Exception {
    BufferedOutputStream fos = null;
    InputStream fis = null;//from ww w . ja  va2s .  c  o  m
    try {
        System.out.println("ftp retrieving " + remotePath);

        fis = ftpClient.retrieveFileStream(remotePath);
        if (fis == null) {
            final int code = ftpClient.getReplyCode();
            System.out.println("error code:" + code + " on " + remotePath);
            if (code == 550)
                return FTPError.FILE_NOT_FOUND;
            else
                return FTPError.READ_ERROR;
        }

        final File parentFolder = localFile.getParentFile();
        if (!parentFolder.exists()) {
            parentFolder.mkdirs();
        }
        fos = new BufferedOutputStream(new FileOutputStream(localFile.getAbsolutePath()));

        final StatusProgressMonitor status = new StatusProgressMonitor(fileSize,
                "Downloading " + localFile.getName() + "... ");
        status.setAllowStdOut(false);

        final int size = 4096;//32768;
        final byte[] buf = new byte[size];
        int n;
        int total = 0;
        while ((n = fis.read(buf, 0, size)) > -1) {
            fos.write(buf, 0, n);
            if (fileSize != null) {
                total += n;
                status.worked(total);
            } else {
                status.working();
            }
        }
        status.done();

        ftpClient.completePendingCommand();
        return FTPError.OK;

    } catch (SocketException e) {
        System.out.println(e.getMessage());
        connect();
        throw new SocketException(e.getMessage() + "\nPlease verify that FTP is not blocked by your firewall.");
    } catch (Exception e) {
        System.out.println(e.getMessage());
        connect();
        return FTPError.READ_ERROR;
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            if (fos != null) {
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:net.ostis.sc.memory.impl.remote.rgp.RGPSession.java

@Override
public void run() {
    try {/*ww w. ja v  a2s.  c  o  m*/
        while (!eventThread.isInterrupted()) {
            RGPCommandId replyId = eventStream.readCommandId();

            if (replyId == RGPCommandId.REQ_ACTIVATE_WAIT) {
                int argsCount = eventStream.readArgsCount();

                RGPWait wait = eventStream.readWait();
                SCWait.Type waitType = eventStream.readWaitType();

                --argsCount;
                --argsCount;

                Object[] params = new Object[argsCount];
                for (int i = 0; i < argsCount; ++i) {
                    RGPArgumentType type = eventStream.readArgType();
                    switch (type) {
                    case SC_ADDR:
                        params[i] = eventStream.readAddrImpl();
                        break;
                    default:
                        break;
                    }
                }

                boolean result = wait.activate(waitType, params);
                eventStream.writeCommandId(RGPCommandId.REP_RETURN);
                eventStream.writeArgsCount(2);
                eventStream.writeRetval(0);
                eventStream.write(result);
            } else if (replyId == RGPCommandId.REQ_ACTIVATE) {
                @SuppressWarnings("unused")
                int argsCount = eventStream.readArgsCount();

                RGPActivity activity = eventStream.readActivity();

                --argsCount;

                RGPAddr _this = eventStream.readAddr();
                RGPAddr prm1 = eventStream.readAddr();
                RGPAddr prm2 = eventStream.readAddr();
                RGPAddr prm3 = eventStream.readAddr();
                activity.activate(this, _this, prm1, prm2, prm3);
            }

            if (closed)
                break;

            eventStream.writeCommandId(RGPCommandId.REP_RETURN);
            eventStream.writeArgsCount(1);
            eventStream.writeRetval(0);
        }
    } catch (SocketException e) {
        return;
    } catch (EOFException e) {
        return;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.jeanpierrehotz.messaging.androidclient.MainActivity.java

/**
 * Diese Methode baut eine Verbindung zum Server auf, von dem wir die Nachrichten bekommen
 *///w  w  w.  jav a2  s  .  com
private void connectToServer() {
    if (!tryingToConnect && !serverReached && online) {
        tryingToConnect = true;

        //          Initialisierung der Serververbindung auf einem eigenen Thread, da Android
        //          keine Netzwerkkommunikation auf dem MainThread erlaubt
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    SharedPreferences serverPreferences = getSharedPreferences(
                            getString(R.string.prefs_serverinformation), MODE_PRIVATE);

                    server = new Socket(
                            serverPreferences.getString(
                                    getString(R.string.prefs_serverinformation_serveradress),
                                    getString(R.string.serverinformation_defaultadress)),
                            serverPreferences.getInt(getString(R.string.prefs_serverinformation_serverport),
                                    getResources().getInteger(R.integer.serverinformation_defaultport)));

                    serverMessageSender = new MessageSender(new DataOutputStream(server.getOutputStream()));
                    serverMessageSender.setPingListener(pingListener);

                    serverMessageListener = new MessageListener(new DataInputStream(server.getInputStream()));
                    serverMessageListener.setClosingDetector(closingDetector);
                    serverMessageListener.setOnMessageReceivedListener(receivedListener);
                    serverMessageListener.bindMessageSender(serverMessageSender);
                    serverMessageListener.setOnDisconnectListener(disconnectListener);
                    serverMessageListener.start();

                    serverMessageSender.changeName(currentName);

                    serverReached = true;
                } catch (SocketException e) {
                    e.printStackTrace();
                    serverReached = false;
                    showDisconnectedErrorMessage();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                tryingToConnect = false;
            }
        }).start();
    }
}

From source file:noThreads.ParseLevel2.java

/**
 *
 * @param theUrl/*from   ww  w.  j  a v  a2s  .c  o m*/
 * @param conAttempts
 * @return
 * @throws IOException
 */
public int getResposeCode(String theUrl, int conAttempts) throws IOException {// throws IOException 
    URL newUrl = new URL(theUrl);
    //These codes are returned to indicate either fault or not.
    int ERROR_CODE = 1000, OK_CODE = 0;

    HttpURLConnection huc = (HttpURLConnection) newUrl.openConnection();
    huc.setRequestMethod("HEAD");
    huc.setRequestProperty("User-Agent", userAgent);
    huc.setReadTimeout(2000);
    huc.connect();
    try {
        return huc.getResponseCode();

    } catch (java.net.SocketException e) {
        if (e.getMessage().equalsIgnoreCase("Unexpected end of file from server")) {
            return OK_CODE; // link still valid so return a small positive int that isn't a http status code
        } else {
            return ERROR_CODE; //error, return a large int that isn't included in any http status code
        }
    } catch (java.net.SocketTimeoutException e) {
        if (e.getMessage().equalsIgnoreCase("Read timed out")) {
            if (conAttempts != MAX_CONNECTION_ATTEMPTS) {
                return getResposeCode(theUrl, conAttempts + 1);
            } else {
                return ERROR_CODE; //ERROR return a large int that isn't included in any http status code
            }
        } else {
            return ERROR_CODE;
        }

    } catch (IOException e) {
        e.printStackTrace();
        return ERROR_CODE; //error, return a large int that isn't included in any http status code      
    }
}

From source file:com.safi.asterisk.handler.SafletEngine.java

public List<String> getLocalIPAddresses() {
    List<String> iplist = new ArrayList<String>();
    NetworkInterface iface = null;
    try {//from w w w.j a v  a2s.  com
        for (Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); ifaces
                .hasMoreElements();) {
            iface = ifaces.nextElement();
            System.out.println("Interface:" + iface.getDisplayName());
            InetAddress ia = null;
            for (Enumeration<InetAddress> ips = iface.getInetAddresses(); ips.hasMoreElements();) {
                ia = ips.nextElement();
                if (Pattern.matches(AbstractConnectionManager.PATTERN_IP, ia.getHostAddress())) {
                    iplist.add(ia.getHostAddress());
                }
            }
        }
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return iplist;
}

From source file:watch.oms.omswatch.actioncenter.helpers.WatchTransDBParser.java

@SuppressWarnings("unused")
private String fetchURLConnectionConfigResponse(String serviceURL) {

    String traceType = OMSApplication.getInstance().getTraceType();
    OMSApplication.getInstance().setTraceType(OMSConstants.TRACE_TYPE_SERVER);
    // AppMonitor

    /*analyzer.startNetworkConnection(serviceURL, OMSMessages.CONNECTION_PREFIX.getValue()
    + connectionID);*///from   w  ww.j  a va 2  s  .  c  om
    ActionCenterHelper actionCenterHelper = new ActionCenterHelper(appContext);
    String configResponse = null;
    String response = "";
    InputStream inputStream = null;
    HttpURLConnection urlConnection = getHttpURLConnection(serviceURL);
    try {
        urlConnection.connect();
    } catch (SocketException e) {
        Log.e(TAG, "SocketException occurred while excecuting the Trans Service." + e.getMessage());
        e.printStackTrace();
        configResponse = OMSMessages.ACTION_CENTER_FAILURE.getValue();
    } catch (IOException e) {
        Log.e(TAG, "IOException occurred while while excecuting the Trans Service." + e.getMessage());
        e.printStackTrace();
        configResponse = OMSMessages.ACTION_CENTER_FAILURE.getValue();

    } catch (Exception e) {
        Log.e(TAG, "Exception occurred while while excecuting the Trans Service." + e.getMessage());
        e.printStackTrace();
        configResponse = OMSMessages.ACTION_CENTER_FAILURE.getValue();
    }
    if (urlConnection != null) {
        // AppMonitor
        //analyzer.updateConnectionStatus(connectionID, true);
        try {
            int statusCode = urlConnection.getResponseCode();
            if (statusCode == OMSConstants.STATUSCODE_OK) {
                inputStream = new BufferedInputStream(urlConnection.getInputStream());
                response = convertStreamToString(inputStream);
                Log.d(TAG, "GETBL Response for HTTPURLConnection:::" + response);
                // Create a Reader from String
                // configResponse = transDBParser(response);

                Reader stringReader = new StringReader(response);
                readJsonStream(stringReader);

                ContentValues contentValues = new ContentValues();
                contentValues.put(OMSDatabaseConstants.TRANSACTION_QUEUE_TYPE,
                        OMSDatabaseConstants.GET_TYPE_REQUEST);
                contentValues.put(OMSDatabaseConstants.TRANSACTION_QUEUE_STATUS,
                        OMSDatabaseConstants.ACTION_STATUS_FINISHED);
                contentValues.put(OMSDatabaseConstants.TRANSACTION_QUEUE_SERVER_URL, serviceURL);
                contentValues.put(OMSDatabaseConstants.TRANSACTION_QUEUE_DATA_TABLE_NAME, tableName);
                actionCenterHelper.insertOrUpdateTransactionFailQueue(contentValues, uniqueRowId, configAppId);
                // AppMonitor
                /*analyzer.receivedConnectionResponse(connectionID,
                   urlConnection.getContentLength(),
                   OMSDatabaseConstants.GET_TYPE_REQUEST);*/

                /*   ServerDBUpdateHelper dbhelper = new ServerDBUpdateHelper(appContext);
                   dbhelper.insertCallTraceTypeData(ConsoleDBConstants.CALL_TRACE_TYPE_TABLE, ""+OMSApplication.getInstance().getAppId());*/
                /*                     Log.i(TAG, "Server URL::"+serviceURL); 
                                     Log.i(TAG, "Server Response time::"+OMSApplication.getInstance().getServerProcessDuration());
                */ Log.i(TAG,
                        "ServerTime::" + OMSApplication.getInstance().getServerProcessDuration() + "\t"
                                + "DBTime::" + OMSApplication.getInstance().getDatabaseProcessDuration() + "\t"
                                + serviceURL);
                OMSApplication.getInstance().setTraceType(traceType);
                configResponse = OMSMessages.BL_SUCCESS.getValue();
            } else {
                Log.e(TAG, "status code[" + urlConnection.getResponseCode() + "] Reason["
                        + urlConnection.getResponseMessage() + "]");

                configResponse = OMSMessages.ACTION_CENTER_FAILURE.getValue();
                ContentValues contentValues = new ContentValues();
                contentValues.put(OMSDatabaseConstants.TRANSACTION_QUEUE_STATUS,
                        OMSDatabaseConstants.ACTION_STATUS_TRIED);
                contentValues.put(OMSDatabaseConstants.TRANSACTION_QUEUE_TYPE,
                        OMSDatabaseConstants.GET_TYPE_REQUEST);
                contentValues.put(OMSDatabaseConstants.TRANSACTION_QUEUE_SERVER_URL, serviceURL);
                contentValues.put(OMSDatabaseConstants.TRANSACTION_QUEUE_DATA_TABLE_NAME, tableName);
                actionCenterHelper.insertOrUpdateTransactionFailQueue(contentValues, uniqueRowId, configAppId);
                inputStream = new BufferedInputStream(urlConnection.getInputStream());
                // AppMonitor
                /*analyzer.receivedConnectionResponse(connectionID,
                urlConnection.getContentLength(),
                OMSDatabaseConstants.GET_TYPE_REQUEST);*/

                response = convertStreamToString(inputStream);
                if (response != null) {
                    return configResponse;

                } else {
                    try {
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put(OMSMessages.ERROR.getValue(), urlConnection.getResponseCode());
                        jsonObject.put(OMSMessages.ERROR_DESCRIPTION.getValue(),
                                urlConnection.getResponseMessage());
                        response = jsonObject.toString();
                    } catch (JSONException e) {
                        Log.e(TAG, "JSONException occurred when is ConfigDBParse Failed." + e.getMessage());
                        e.printStackTrace();
                    }
                }
            }
        } catch (SocketException e) {
            Log.e(TAG, "SocketException occurred while excecuting the Trans Service." + e.getMessage());
            e.printStackTrace();
            configResponse = OMSMessages.ACTION_CENTER_FAILURE.getValue();
        } catch (IOException e) {
            Log.e(TAG, "IOException occurred while while excecuting the Trans Service." + e.getMessage());
            e.printStackTrace();
            configResponse = OMSMessages.ACTION_CENTER_FAILURE.getValue();

        } catch (Exception e) {
            Log.e(TAG, "Exception occurred while while excecuting the Trans Service." + e.getMessage());
            e.printStackTrace();
            configResponse = OMSMessages.ACTION_CENTER_FAILURE.getValue();
        }
    } else {
        configResponse = OMSMessages.ACTION_CENTER_FAILURE.getValue();
    }
    return configResponse;
}

From source file:org.monome.pages.configuration.Configuration.java

/**
 * Initializes the Ableton OSC out port//from w ww .j  av a  2  s  .co m
 */
public void initAbletonOSCOut() {
    try {
        this.abletonOSCPortOut = new OSCPortOut(InetAddress.getByName(this.abletonHostname),
                this.abletonOSCOutPortNumber);
    } catch (SocketException e) {
        e.printStackTrace();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
}

From source file:org.monome.pages.configuration.Configuration.java

/**
 * Initializes the Ableton OSC in port//www . j  av a  2 s.  com
 */
public void initAbletonOSCIn() {
    try {
        if (this.abletonOSCPortIn != null) {
            this.abletonOSCPortIn.stopListening();
            this.abletonOSCPortIn.close();
        }
        this.abletonOSCPortIn = new OSCPortIn(this.abletonOSCInPortNumber);
        this.abletonOSCPortIn.addListener("/live/track", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/track/info", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/name/track", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/clip/info", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/state", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/mute", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/arm", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/solo", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/scene", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/tempo", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/overdub", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/refresh", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/reset", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/devicelist", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/device", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/device/allparam", this.abletonOSCListener);
        this.abletonOSCPortIn.addListener("/live/device/param", this.abletonOSCListener);
        this.abletonOSCPortIn.startListening();
    } catch (SocketException e) {
        e.printStackTrace();
    }
}