List of usage examples for java.net SocketException getMessage
public String getMessage()
From source file:com.btobits.automator.fix.utils.FileMessageFactory.java
public void loadInternal(ITcpProccesor inProcessor, int repeatDelay, String nameClient, int inTimeOut) throws Exception { try {/* ww w. j av a 2 s. c o m*/ Scanner scanner = new Scanner(new FileInputStream(file)); //scanner.useDelimiter(delimeter); while (scanner.hasNextLine()) { final String line = scanner.nextLine(); inProcessor.sendMessage(new ITcpMessage() { public byte[] toRawMessage() { return line.getBytes(); } public String getMessageAsString() { return line; } }, inTimeOut); inProcessor.log(line, false); if (repeatDelay > 0) { try { Thread.sleep(repeatDelay); } catch (Exception e) { } } } } catch (SocketException ex) { throw new BuildException(ex.getMessage()); } catch (Exception ex) { throw new Exception("Error send data from file, error: " + ex.getMessage(), ex); } }
From source file:org.openhab.binding.orvibo.internal.discovery.SocketDiscoveryService.java
@Override protected void activate(Map<String, Object> configProperties) { try {/*from w w w. jav a 2 s.c om*/ s20Client = S20Client.getInstance(); super.activate(configProperties); } catch (SocketException ex) { logger.error("Error occurred while activating S20 discovery service: {}", ex.getMessage(), ex); } }
From source file:net.shopxx.plugin.ftpStorage.FtpStoragePlugin.java
@Override public void upload(String path, File file, String contentType) { PluginConfig pluginConfig = getPluginConfig(); if (pluginConfig != null) { String host = pluginConfig.getAttribute("host"); Integer port = Integer.valueOf(pluginConfig.getAttribute("port")); String username = pluginConfig.getAttribute("username"); String password = pluginConfig.getAttribute("password"); FTPClient ftpClient = new FTPClient(); InputStream inputStream = null; try {/*from w w w .j a v a 2 s.c om*/ inputStream = new BufferedInputStream(new FileInputStream(file)); ftpClient.connect(host, port); ftpClient.login(username, password); ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) { String directory = StringUtils.substringBeforeLast(path, "/"); String filename = StringUtils.substringAfterLast(path, "/"); if (!ftpClient.changeWorkingDirectory(directory)) { String[] paths = StringUtils.split(directory, "/"); String p = "/"; ftpClient.changeWorkingDirectory(p); for (String s : paths) { p += s + "/"; if (!ftpClient.changeWorkingDirectory(p)) { ftpClient.makeDirectory(s); ftpClient.changeWorkingDirectory(p); } } } ftpClient.storeFile(filename, inputStream); ftpClient.logout(); } } catch (SocketException e) { throw new RuntimeException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(inputStream); try { if (ftpClient.isConnected()) { ftpClient.disconnect(); } } catch (IOException e) { } } } }
From source file:org.openhab.binding.orvibo.handler.S20Handler.java
private void configure() { try {/*from w w w . j a v a2 s . c om*/ client = S20Client.getInstance(); String deviceId = thing.getUID().getId(); socket = client.socketWithDeviceId(deviceId); socket.addSocketStateListener(this); socket.findOnNetwork(); subscribeHandler = scheduler.scheduleWithFixedDelay(subscribeTask, 0, refreshInterval, TimeUnit.SECONDS); updateStatus(ThingStatus.ONLINE); } catch (SocketException ex) { logger.error("Error occurred while initializing S20 handler: {}", ex.getMessage(), ex); } }
From source file:org.rifidi.emulator.io.comm.ip.udp.UDPCommunication.java
/** * A constructor for a UDPCommunication. Takes in the local IP/port to bind * to and and the remote IP/port to send data to. * /* w w w .j av a 2s. co m*/ * @param initialPowerState * The initial power state. * @param initialConnectionState * The initial connection state. * @param localIP * The local IP to bind to. * @param localPort * The local port to bind to. * @param remoteIP = * new DatagramSocket() The remote IP to send data to. * @param remotePort * The remote port to send data to. * @param protocol * The protocol that this session will be using. */ public UDPCommunication(Protocol prot, ControlSignal<Boolean> powerControlSignal, ControlSignal<Boolean> connectionControlSignal, String localIP, int localPort, boolean outputOnly) throws CommunicationException { /* call the super constructor for ip communication and set vars */ super(UDPOffCommunicationPowerState.getInstance(), UDPConnectionlessCommunicationConnectionState.getInstance(), prot, powerControlSignal, connectionControlSignal, localIP, localPort, null, 0); /* Validate that the ip parameters passed in are not null */ if (localIP == null || !GeneralFormattingUtility.isValidIPPort(localPort)) { throw new CommunicationException("Invalid ip Parameters"); } /* This variable is used to indicate outgoing UPD packets only */ this.outputOnly = outputOnly; try { newSock = new DatagramSocket(null); } catch (SocketException e) { logger.warn(e.getMessage()); } this.prot = prot; System.out.println("UDP communication created successfuly"); }
From source file:org.sofun.platform.opta.ftp.FTPClientWrapper.java
/** * Establishes a connection w/ the FTP server. * /*from w w w . j a va 2 s . co m*/ * @throws OptaException */ public void connect() throws OptaException { if (client == null || !client.isAvailable()) { client = new FTPClient(); } try { client.connect(host, port); int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { client.disconnect(); throw new OptaException("FTP server refused connection."); } } catch (SocketException e) { throw new OptaException(e.getMessage()); } catch (IOException e) { if (client.isConnected()) { try { client.disconnect(); } catch (IOException f) { // do nothing: just spit stack trace. f.printStackTrace(); } } throw new OptaException(e.getMessage()); } try { if (!client.login(username, password)) { client.logout(); throw new OptaException("Cannot login..."); } client.enterLocalPassiveMode(); } catch (Exception e) { throw new OptaException(e.getMessage()); } }
From source file:org.squidy.manager.protocol.osc.OSCServer.java
public OSCServer(String addressOut, int portOut, int portIn, Endian endian) { this(addressOut, portOut, endian); try {//from w ww . j av a 2s . c o m oscPortIn = new OSCPortIn(portIn, endian); } catch (SocketException e) { throw new SquidyException(e.getMessage(), e); } }
From source file:org.squidy.manager.protocol.osc.OSCServer.java
public OSCServer(String addressOut, int portOut) { try {//from ww w . j a v a 2 s . com oscPortOut = new OSCPortOut(InetAddress.getByName(addressOut), portOut); } catch (SocketException e) { throw new SquidyException(e.getMessage(), e); } catch (UnknownHostException e) { throw new SquidyException(e.getMessage(), e); } }
From source file:org.memento.client.Main.java
public void go(String[] args) throws ParseException, ClassCastException { boolean exit; CommandLine cmd;// ww w . java 2 s . c o m CommandLineParser parser; parser = new PosixParser(); cmd = parser.parse(this.opts, args); exit = false; if (cmd.hasOption("h") || cmd.hasOption("help")) { this.printHelp(0); } if (cmd.hasOption("debug")) { Handler console = new ConsoleHandler(); console.setLevel(Level.FINEST); Main.LOGGER.addHandler(console); Main.LOGGER.setLevel(Level.FINEST); } else { Main.LOGGER.setLevel(Level.OFF); } if (!cmd.hasOption("p")) { System.out.println("No port defined!"); this.printHelp(2); } Main.LOGGER.fine("Main - Listen port " + cmd.getOptionValue("p")); try (Serve serve = new Serve(Integer.parseInt(cmd.getOptionValue("p")));) { if (cmd.hasOption("l")) { Main.LOGGER.fine("Listen address " + cmd.getOptionValue("l")); serve.setAddress(cmd.getOptionValue("l")); } if (cmd.hasOption("S")) { Main.LOGGER.fine("Main - SSL enabled"); Section section = this.getOptions("ssl", cmd.getOptionValue("S")); serve.setSSL(true); serve.setSSLkey(section.get("key")); if (section.containsKey("password")) { Main.LOGGER.fine("Main - SSL key password exists"); serve.setSSLpass(section.get("password")); } } serve.open(); while (!exit) { try { exit = serve.listen(); } catch (SocketException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getMessage()); } } } catch (BindException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getMessage()); } catch (IllegalArgumentException | SocketException | UnknownHostException | NullPointerException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.navercorp.pinpoint.profiler.sender.UdpDataSender.java
private DatagramSocket createSocket(String host, int port, int timeout, int sendBufferSize) { try {// www .java 2s.com final DatagramSocket datagramSocket = new DatagramSocket(); datagramSocket.setSoTimeout(timeout); datagramSocket.setSendBufferSize(sendBufferSize); if (logger.isInfoEnabled()) { final int checkSendBufferSize = datagramSocket.getSendBufferSize(); if (sendBufferSize != checkSendBufferSize) { logger.info("DatagramSocket.setSendBufferSize() error. {}!={}", sendBufferSize, checkSendBufferSize); } } final InetSocketAddress serverAddress = new InetSocketAddress(host, port); datagramSocket.connect(serverAddress); return datagramSocket; } catch (SocketException e) { throw new IllegalStateException("DatagramSocket create fail. Cause" + e.getMessage(), e); } }