Hi I wanted to create a client side socket which connects to the host and sends data.
But the problem is the client connects to it, but doesn't send data.Here's the code:
import java.net.*; import java.io.*; import java.rmi.UnknownHostException; class Client{ public static void main(String args[]){ Socket sock; BufferedReader br; PrintWriter pr; String str; try { sock = new Socket("localhost", 80); System.out.println("Connected to server"); br = new BufferedReader(new InputStreamReader( sock.getInputStream())); while ((str = br.readLine())!= null) { System.out.println(str); } System.out.println("Reading complete!"); pr = new PrintWriter(new OutputStreamWriter( sock.getOutputStream())); pr.println("Hello."); System.out.println("Message sent"); pr.close(); br.close(); sock.close(); }catch (UnknownHostException e) { System.out.println("Error"); } catch(IOException e){ System.out.println("Error"); } } }