Skip to content

Instantly share code, notes, and snippets.

@jpt1122
Created September 21, 2013 17:56
Show Gist options
  • Save jpt1122/6652702 to your computer and use it in GitHub Desktop.
Save jpt1122/6652702 to your computer and use it in GitHub Desktop.
import java.net.*;
import java.io.*;
public class SocketServer
{
public static void main(String args[]) throws IOException
{
ServerSocket s = new ServerSocket(4444);
try
{
while(true)
{
Socket s1=s.accept();
InputStream s1In = s1.getInputStream();
DataInputStream dis = new DataInputStream(s1In);
String st = new String (dis.readUTF());
System.out.println(st);
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(s);
dos.close();
s1out.close();
s1.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment