Saturday, August 7, 2010

SOCKET PROGRAMMING-SERVER ECHO

import java.io.*;
import java.net.*;
import java.lang.String;
public class serverecho
{
    public static void main(String args[])throws Exception
    {
        ServerSocket ss = new ServerSocket(1234);
        Socket s = ss.accept();
        DataInputStream in = new DataInputStream(s.getInputStream());
        DataOutputStream out = new DataOutputStream(s.getOutputStream());
        String str;
        System.out.println("\n server side");
        while (true)
        {
            str = in.readLine();
            out.writeBytes(str + "\n");
            System.out.println("msg from client");
            System.out.println(str + "\n");
        }
    }
}

No comments:

Post a Comment