Created
March 12, 2016 14:32
-
-
Save waqasraza123/02cf2ac5fe68303cd385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// File Name GreetingClient.java | |
import java.net.*; | |
import java.util.Scanner; | |
import java.io.*; | |
public class Client | |
{ | |
public static Socket sc; | |
public static void main(String [] args) | |
{ | |
try | |
{ | |
InetAddress address = InetAddress.getByName("localhost"); | |
sc = new Socket(address, 9000); | |
OutputStreamWriter osWriter = new OutputStreamWriter(sc.getOutputStream()); | |
BufferedWriter bw = new BufferedWriter(osWriter); | |
bw.write("Hello Server"); | |
bw.flush(); | |
//read message from server | |
InputStreamReader in = new InputStreamReader(sc.getInputStream()); | |
BufferedReader br = new BufferedReader(in); | |
System.out.println(br.readLine()); | |
}catch(IOException e) | |
{ | |
e.printStackTrace(); | |
}finally{ | |
try { | |
sc.close(); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment