List of usage examples for java.net SocketException toString
public String toString()
From source file:velo.adapters.GenericTelnetAdapter.java
public boolean connect() throws AdapterException { try {/* ww w .j a v a2 s . c o m*/ logger.debug("Connecting by \'" + velo.adapters.GenericTelnetAdapter.class.getName() + "\', to resource: \'" + getResource().getDisplayName() + "\'"); //Load confiugration parameters if neccessary if (!isInitiatedStandalone()) { host = getResourceDescriptor().getString("specific.host"); port = getResourceDescriptor().getInt("specific.port"); terminalType = getResourceDescriptor().getString("specific.terminal_type"); timeout = getResourceDescriptor().getInt("specific.timeout"); } if (logger.isTraceEnabled()) { logger.trace("Connecting to host: " + host); logger.trace("Connecting to port: " + port); logger.trace("Connecting with terminal type: " + terminalType); logger.trace("Setting timeout (in MS): " + timeout); } telnetClient = new org.apache.commons.net.telnet.TelnetClient(terminalType); telnetClient.connect(host, port); //Set timeout telnetClient.setSoTimeout(timeout); in = telnetClient.getInputStream(); out = new java.io.PrintStream(telnetClient.getOutputStream()); setConnected(true); setTelnetClient(telnetClient); return true; } catch (SocketException ex) { logger.warn(ex.toString()); throw new AdapterException(ex); } catch (IOException ex) { logger.warn(ex.toString()); throw new AdapterException(ex); } }
From source file:org.openhab.binding.plclogo.internal.discovery.PLCDiscoveryService.java
@Override protected void startScan() { stopScan();//from www. ja v a 2s . co m logger.debug("Start scan for LOGO! bridge"); Enumeration<NetworkInterface> devices = null; try { devices = NetworkInterface.getNetworkInterfaces(); } catch (SocketException exception) { logger.warn("LOGO! bridge discovering: {}.", exception.toString()); } Set<String> addresses = new TreeSet<>(); while ((devices != null) && devices.hasMoreElements()) { NetworkInterface device = devices.nextElement(); try { if (!device.isUp() || device.isLoopback()) { continue; } } catch (SocketException exception) { logger.warn("LOGO! bridge discovering: {}.", exception.toString()); } for (InterfaceAddress iface : device.getInterfaceAddresses()) { InetAddress address = iface.getAddress(); if (address instanceof Inet4Address) { String prefix = String.valueOf(iface.getNetworkPrefixLength()); SubnetUtils utilities = new SubnetUtils(address.getHostAddress() + "/" + prefix); addresses.addAll(Arrays.asList(utilities.getInfo().getAllAddresses())); } } } ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); for (String address : addresses) { try { executor.execute(new Runner(address)); } catch (RejectedExecutionException exception) { logger.warn("LOGO! bridge discovering: {}.", exception.toString()); } } try { executor.awaitTermination(CONNECTION_TIMEOUT * addresses.size(), TimeUnit.MILLISECONDS); } catch (InterruptedException exception) { logger.warn("LOGO! bridge discovering: {}.", exception.toString()); } executor.shutdown(); stopScan(); }
From source file:net.sourceforge.atunes.kernel.modules.player.vlcplayer.VlcTelnetClient.java
protected VlcTelnetClient(String newServer, int newPort) throws VlcTelnetClientException { // wait a title time for vlc process to be created try {/*from w w w . j ava2s . co m*/ Thread.sleep(1000); } catch (InterruptedException e) { //we do nothing special //e.printStackTrace(); } // Connect to the specified server logger.debug(LogCategories.NETWORK, "VlcTelnetClient : Connecting to port : " + newPort + " on server : " + newServer); try { telnet.connect(newServer, newPort); } catch (SocketException se) { se.printStackTrace(); throw new VlcTelnetClientException( "Error while connecting to : " + newServer + " on : " + newPort + " : " + se.toString(), se); } catch (IOException ioe) { ioe.printStackTrace(); throw new VlcTelnetClientException( "Error while connecting to : " + newServer + " on : " + newPort + " : " + ioe.toString(), ioe); } // Get input and output stream references try { in = telnet.getInputStream(); out = new PrintStream(telnet.getOutputStream()); //throw new Exception("Can't write or read form telnet client"); } catch (Exception ex) { throw new VlcTelnetClientException("Can't write or read form telnet client", ex); } }
From source file:TcpClient.java
/** Initialize a server socket for communicating with the client. */ private void initServerSocket() { this.inboundAddr = new InetSocketAddress(COMM_PORT); try//w w w . j a va 2s. c om { this.serverSocket = new java.net.ServerSocket(COMM_PORT); assert this.serverSocket.isBound(); if (this.serverSocket.isBound()) { System.out.println("SERVER inbound data port " + this.serverSocket.getLocalPort() + " is ready and waiting for client to connect..."); } } catch (SocketException se) { System.err.println("Unable to create socket."); System.err.println(se.toString()); System.exit(1); } catch (IOException ioe) { System.err.println("Unable to read data from an open socket."); System.err.println(ioe.toString()); System.exit(1); } }
From source file:com.cellbots.httpserver.HttpCommandServer.java
public String getLocalIpAddress() { try {// www . jav a 2 s .c o m for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e("", ex.toString()); } return null; }
From source file:com.almarsoft.GroundhogReader.ComposeActivity.java
private void postMessage() { AsyncTask<Void, Void, Void> messagePosterTask = new AsyncTask<Void, Void, Void>() { String mPostingErrorMessage = null; @Override/*from w w w . ja va 2 s . c o m*/ protected Void doInBackground(Void... arg0) { MessagePosterLib poster = new MessagePosterLib(mCurrentGroup, mEdit_Groups.getText().toString(), mEdit_Body.getText().toString(), mEdit_Subject.getText().toString(), mReferences, mMessageID, ComposeActivity.this); try { poster.postMessage(); } catch (SocketException e) { e.printStackTrace(); mPostingErrorMessage = e.toString(); } catch (EncoderException e) { e.printStackTrace(); mPostingErrorMessage = e.toString(); } catch (IOException e) { e.printStackTrace(); mPostingErrorMessage = e.toString(); } catch (ServerAuthException e) { e.printStackTrace(); mPostingErrorMessage = e.toString(); } catch (UsenetReaderException e) { e.printStackTrace(); mPostingErrorMessage = e.toString(); } return null; } protected void onPostExecute(Void arg0) { try { dismissDialog(ID_DIALOG_POSTING); } catch (IllegalArgumentException e) { } if (mPostingErrorMessage != null) { new AlertDialog.Builder(ComposeActivity.this).setTitle(getString(R.string.error_posting)) .setMessage(mPostingErrorMessage).setNeutralButton(getString(R.string.close), null) .show(); mPostingErrorMessage = null; } else { setResult(RESULT_OK); finish(); } } }; // End messagePosterTask String groups = mEdit_Groups.getText().toString(); if (groups == null || groups.trim().length() == 0) { new AlertDialog.Builder(ComposeActivity.this).setTitle(getString(R.string.empty_groups)) .setMessage(getString(R.string.must_select_group)).setNeutralButton("Close", null).show(); } else { showDialog(ID_DIALOG_POSTING); messagePosterTask.execute(); } }
From source file:com.honeywell.printer.net.autobaln_websocket.WebSocketWriter.java
public void writeMessageToBuffer(Message message) { try {/*w w w . ja v a2 s .com*/ mApplicationBuffer.clear(); processMessage(message.obj); mApplicationBuffer.flip(); mOutputStream.write(mApplicationBuffer.array(), mApplicationBuffer.position(), mApplicationBuffer.limit()); } catch (SocketException e) { Log.e(TAG, "run() : SocketException (" + e.toString() + ")"); notify(new WebSocketMessage.ConnectionLost()); } catch (IOException e) { Log.e(TAG, "run() : IOException (" + e.toString() + ")"); } catch (Exception e) { notify(new WebSocketMessage.Error(e)); } }
From source file:me.schiz.jmeter.protocol.pop3.sampler.POP3Sampler.java
private SampleResult sampleConnect(SampleResult sr) { POP3Client client;//from w w w. j av a2 s .com if (getUseSSL()) { client = new POP3SClient(true); // } else if(getUseSTARTTLS()) { // client = new POP3SClient(false); } else { client = new POP3Client(); } StringBuilder requestBuilder = new StringBuilder(); try { //String request = "CONNECT \n"; requestBuilder.append("CONNECT\n"); requestBuilder.append("Host : " + getHostname() + ":" + getPort() + "\n"); requestBuilder.append("Connect Timeout: " + getConnectionTimeout() + "\n"); requestBuilder.append("Socket Timeout: " + getSoTimeout() + "\n"); requestBuilder.append("Client : " + getClient() + "\n"); if (getUseSSL()) requestBuilder.append("SSL : true\n"); else requestBuilder.append("SSL : false\n"); // if(getUseSTARTTLS()) request += "STARTTLS : true\n"; // else request += "STARTTLS : false\n"; sr.setRequestHeaders(requestBuilder.toString()); sr.sampleStart(); client.setConnectTimeout(getConnectionTimeout()); client.connect(getHostname(), getPort()); if (client.isConnected()) { SessionStorage.proto_type protoType = SessionStorage.proto_type.PLAIN; if (getUseSSL()) protoType = SessionStorage.proto_type.SSL; // if(getUseSSL() && !getUseSTARTTLS()) protoType = SessionStorage.proto_type.SSL; // if(!getUseSSL() && getUseSTARTTLS()) protoType = SessionStorage.proto_type.STARTTLS; SessionStorage.getInstance().putClient(getSOClient(), client, protoType); client.setSoTimeout(getSoTimeout()); client.setTcpNoDelay(getTcpNoDelay()); sr.setResponseCode(RC_200); sr.setResponseData(client.getReplyString().getBytes()); sr.setSuccessful(true); } else { sr.setResponseCode(RC_500); sr.setSuccessful(false); } } catch (SocketException se) { sr.setResponseMessage(se.toString()); sr.setSuccessful(false); sr.setResponseCode(se.getClass().getName()); log.error("client `" + client + "` ", se); } catch (IOException ioe) { sr.setResponseMessage(ioe.toString()); sr.setSuccessful(false); sr.setResponseCode(ioe.getClass().getName()); log.error("client `" + client + "` ", ioe); } sr.sampleEnd(); return sr; }