Java Socket Create getSocketFromString(String s)

Here you can find the source of getSocketFromString(String s)

Description

get Socket From String

License

LGPL

Declaration

public static Socket getSocketFromString(String s) throws UnknownHostException, IOException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.IOException;

import java.net.Socket;

import java.net.UnknownHostException;

public class Main {
    public static Socket getSocketFromString(String s) throws UnknownHostException, IOException {
        Socket result = null;/*from  www  . j  a v  a2s .  c om*/
        String[] splitAddress = s.split(":");
        if (splitAddress.length > 1) {
            String hostname = splitAddress[0];
            int port = Integer.parseInt(splitAddress[1]);
            result = new Socket(hostname, port);
        }
        return result;
    }
}

Related

  1. getSocket()
  2. getSocket(String host, int port)
  3. getSocket(String host, int port)
  4. getSocket(String host, int port, int timeout)
  5. getSocket(String i_HostName, int i_Port)
  6. getSocketId(Socket socket)
  7. getSocketInRange(int minPort, int maxPort, boolean random)
  8. getSocketToBytes(String ip, int port, String packet, int timeout)
  9. getSocketToProxyServer(String host, int port)