Skip to content

Instantly share code, notes, and snippets.

@waqasraza123
Created March 12, 2016 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waqasraza123/02cf2ac5fe68303cd385 to your computer and use it in GitHub Desktop.
Save waqasraza123/02cf2ac5fe68303cd385 to your computer and use it in GitHub Desktop.
// 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