List of usage examples for java.net Socket getOutputStream
public OutputStream getOutputStream() throws IOException
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 www . j a v a 2 s .c o m s.close(); } }
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 w w . j av 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 . j a v a 2s. co m*/ s.close(); } }
From source file:SquareClient.java
public static void main(String args[]) throws Exception { String server = args[0];// ww w .j ava2 s . c om int port = Integer.parseInt(args[1]); double value = Double.valueOf(args[2]).doubleValue(); Socket s = new Socket(server, port); OutputStream os = s.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); dos.writeDouble(value); InputStream is = s.getInputStream(); DataInputStream dis = new DataInputStream(is); value = dis.readDouble(); System.out.println(value); s.close(); }
From source file:SecureServer.java
public static void main(String[] args) throws Exception { ServerSocketFactory ssf = SSLServerSocketFactory.getDefault(); SSLServerSocket ss = (SSLServerSocket) ssf.createServerSocket(98999); Socket sock = ss.accept(); ss.close();/* w w w .j a va 2 s . co m*/ OutputStream rawOut = sock.getOutputStream(); PrintWriter out = new PrintWriter(new OutputStreamWriter(rawOut)); out.println(new java.util.Date().toString()); out.flush(); sock.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { byte buff[] = new byte[1024]; InetAddress addr = InetAddress.getByName("www.java2s.com"); Socket s = new Socket(addr, 80); OutputStream output = s.getOutputStream(); InputStream input = s.getInputStream(); String GetCmd = "GET /index.html HTTP/1.0\r\n\r\n"; GetCmd.getBytes(0, GetCmd.length(), buff, 0); output.write(buff);// w w w . jav a2s . c o m input.read(buff, 0, buff.length); System.out.println(new String(buff, 0)); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault(); Socket s = sf.createSocket(HOST, PORT); OutputStream out = s.getOutputStream(); out.write("\nConnection established.\n\n".getBytes()); out.flush();// www . ja va 2 s . c o m int theCharacter = 0; theCharacter = System.in.read(); while (theCharacter != '~') // The '~' is an escape character to exit { out.write(theCharacter); out.flush(); theCharacter = System.in.read(); } out.close(); s.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(1234); while (true) { System.out.println("Listening"); Socket sock = ssock.accept(); DataOutputStream dstream = new DataOutputStream(sock.getOutputStream()); dstream.writeFloat(3.14159265f); dstream.close();//from w ww . j av a2 s . c o m sock.close(); } }
From source file:MainClass.java
public static void main(String args[]) throws Exception { ServerSocket ss = new ServerSocket(80); while (true) { Socket s = ss.accept(); PrintStream out = new PrintStream(s.getOutputStream()); BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream())); String info = null;//from ww w . j av a 2s . c om while ((info = in.readLine()) != null) { System.out.println("now got " + info); if (info.equals("")) break; } out.println("HTTP/1.0 200 OK"); out.println("MIME_version:1.0"); out.println("Content_Type:text/html"); String c = "<html> <head></head><body> <h1> hi</h1></Body></html>"; out.println("Content_Length:" + c.length()); out.println(""); out.println(c); out.close(); s.close(); in.close(); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { int port = 2000; ServerSocket srv = new ServerSocket(port); // Wait for connection from client. Socket socket = srv.accept(); BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); wr.write("aString"); wr.flush();/*from w w w .ja v a 2 s . c o m*/ }