Skip to content

Instantly share code, notes, and snippets.

@jpt1122
Created September 21, 2013 17:55
Show Gist options
  • Save jpt1122/6652694 to your computer and use it in GitHub Desktop.
Save jpt1122/6652694 to your computer and use it in GitHub Desktop.
import java.net.*;
import java.io.*;
import java.util.*;
public class SocketClient
{
public static void main(String args[]) throws IOException
{
Socket s1 = new Socket("localhost",4444);
while(true)
{
OutputStream s1out = s1.getOutputStream();
DataOutputStream dos = new DataOutputStream (s1out);
System.out.print("Enter String Which You Want To Send:- ");
Scanner s=new Scanner(System.in);
String str=s.next();
dos.writeUTF(str);
InputStream s1In = s1.getInputStream();
DataInputStream dis = new DataInputStream(s1In);
String st = new String (dis.readUTF());
System.out.println(st);
dis.close();
s1In.close();
s1.close();
}//end while
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment