Java Socket Create getSocket(String i_HostName, int i_Port)

Here you can find the source of getSocket(String i_HostName, int i_Port)

Description

get Socket

License

Open Source License

Declaration

public final static Socket getSocket(String i_HostName, int i_Port) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.net.InetAddress;

import java.net.Socket;

public class Main {

    public final static Socket getSocket(String i_HostName, int i_Port) {
        if (i_Port <= 0 || i_Port > 65535) {
            throw new IndexOutOfBoundsException("Port isn't between 0 and 65535.");
        }// w w  w.ja  va  2  s . com

        Socket v_Ret = null;
        try {
            InetAddress v_InetAddress = InetAddress.getByName(i_HostName);

            if (v_InetAddress != null) {
                v_Ret = new Socket(v_InetAddress, i_Port);
            }
        } catch (Exception exce) {
            v_Ret = null;
        }

        return v_Ret;
    }
}

Related

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