List of usage examples for java.net Socket close
public synchronized void close() throws IOException
From source file:WebPing.java
public static void main(String[] args) { try {/* ww w. j a v a 2 s . c om*/ InetAddress addr; Socket sock = new Socket("www.java2s.com", 80); addr = sock.getInetAddress(); System.out.println("Connected to " + addr); sock.close(); } catch (java.io.IOException e) { System.out.println("Can't connect to " + args[0]); System.out.println(e); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept(); PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close();/*from w ww .j a v a 2 s. co m*/ s.close(); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { System.setProperty("javax.net.ssl.keyStore", "mykeystore"); System.setProperty("javax.net.ssl.keyStorePassword", "wshr.ut"); SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept(); PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close();/*from w w w . ja v a2 s .c om*/ s.close(); } }
From source file:com.sm.test.TestConnect.java
public static void main(String[] args) throws Exception { String[] opts = new String[] { "-host", "-port", "-times" }; String[] defaults = new String[] { "ssusd003.ir.dc", "6666", "500" }; String[] paras = getOpts(args, opts, defaults); String host = paras[0];//from ww w .ja v a 2 s .c o m int port = Integer.valueOf(paras[1]); int timeout = Integer.valueOf(paras[2]); // logger.info("pos="+"/test/".indexOf("/")); // logger.info("/test/".substring(0, "/test/".indexOf("/"))); // BuildClusterNodes bc = new BuildClusterNodes("./clusterStore/src/test/resources/config.xml"); // logger.info(bc.build().toString()); // BuildStoreConfig bs = new BuildStoreConfig("./clusterStore/src/test/resources/config.xml"); // logger.info(bs.build().toString()); long begin = System.currentTimeMillis(); SocketAddress inet = new InetSocketAddress(host, port); try { Socket socket = new Socket(); socket.connect(inet, timeout); socket.close(); } catch (Exception ex) { logger.error("ex " + ex.toString()); } logger.info("time in Socket ms " + (System.currentTimeMillis() - begin)); // begin = System.currentTimeMillis(); // try { // TCPClient client = TCPClient.start(host, port); // client.close(); // } catch (Exception ex) { // logger.error( ex.getMessage()); // } // logger.info("time in TCPClient ms "+(System.currentTimeMillis() - begin)); }
From source file:MTServerBase.java
static public void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(8080); while (true) { Socket esock = null; esock = ssock.accept();//from w w w. jav a2 s. c o m MTServerBase t = new MTServerBase(); t.socket = esock; t.start(); esock.close(); } }
From source file:ServerSocketDemo.java
public static void main(String args[]) throws Exception { int port = Integer.parseInt(args[0]); ServerSocket ss = new ServerSocket(port); while (true) { Socket s = ss.accept(); OutputStream os = s.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); dos.writeInt(1);//from w w w . j ava 2 s.c om s.close(); } }
From source file:SocketDemo.java
public static void main(String args[]) throws Exception { String server = args[0];//from ww w .ja va2s.c o m int port = Integer.parseInt(args[1]); Socket s = new Socket(server, port); InputStream is = s.getInputStream(); DataInputStream dis = new DataInputStream(is); System.out.println(dis.readInt()); s.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { SSLContext context;/* w w w .j a va 2s .co m*/ KeyManagerFactory kmf; KeyStore ks; char[] storepass = "newpass".toCharArray(); char[] keypass = "wshr.ut".toCharArray(); String storename = "newstore"; context = SSLContext.getInstance("TLS"); kmf = KeyManagerFactory.getInstance("SunX509"); FileInputStream fin = new FileInputStream(storename); ks = KeyStore.getInstance("JKS"); ks.load(fin, storepass); kmf.init(ks, keypass); context.init(kmf.getKeyManagers(), null, null); SSLServerSocketFactory ssf = context.getServerSocketFactory(); ServerSocket ss = ssf.createServerSocket(5432); while (true) { Socket s = ss.accept(); PrintStream out = new PrintStream(s.getOutputStream()); out.println("Hi"); out.close(); s.close(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { int port = 37; ServerSocket server = new ServerSocket(port); while (true) { Socket connection = null; connection = server.accept();//from w ww . j a v a 2s . c o m OutputStream out = connection.getOutputStream(); out.write(123); out.flush(); connection.close(); } }
From source file:Main.java
public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); Hashtable hash = new Hashtable(); hash.put("A", "a"); while (true) { Socket sock = ssock.accept(); ObjectOutputStream ostream = new ObjectOutputStream(sock.getOutputStream()); ostream.writeObject(hash);/*from w ww . j a v a 2s. c o m*/ ostream.close(); sock.close(); } }