I have created a simple TCP chat application for testing the network binding or connection establishment with my friend's system.


using that program my friend can just send me text and i have written not code to reply him with a text

but when i run the server program(tcpserver.java) in my system and he run the client program(tcpclient.java) my server program runs and he can compile the client program but can't run it !!!


error occurring as Unknownhost exception and main function not found error !!!


the program that we used is as follows


tcpserver.java


Java Code:
import java.net.*;
	import java.io.*;
	public class tcpserver
	{
	    public static void main(String args[]) throws IOException
	    {
		ServerSocket s1=null;
		try
		{
		   s1=new ServerSocket(98);
		}
		catch(IOException e)
		{
		   System.err.println("Could not find port 98");
		   System.exit(1);
		}
		Socket c=null;
		try
		{
		   c=s1.accept();
		   System.out.println("Connection from"+c);
		}
		
                                  catch(IOException e)
		{
		   System.out.println("Accept failed");
		   System.exit(1);
		}
		PrintWriter out=new PrintWriter(c.getOutputStream(),true);
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		System.out.println("I am ready,type now");
		String l=in.readLine();
		while(l!=null)
		{
		   out.println(l);
		}
		out.close();
		in.close();
		c.close();
		s1.close();
	    }
	}


the client program that my friend executed is

tcpclient.java


Java Code:
import java.net.*;
	import java.io.*;
	public class tcpclient
	{
	    public static void main(String arg[]) throws IOException
	    {
		Socket s=null;
		BufferedReader b=null;
		try
		{
		   s=new Socket(InetAddress.getByName("116.x.y.z"),98);//116.x.y.x is my ipaddress for which establishes the tcp connection
		   b=new BufferedReader(new InputStreamReader(s.getInputStream()));
		}
		catch(UnknownHostException u)
		{
		   System.err.println("I dont know host");
		   System.exit(0);
		}
		String inp;
		while((inp=b.readLine())!=null)
		{
		   System.out.println(inp);
		   break;
		}
		b.close();
		s.close();
	    }
	}

what i have to do further !!!

i m really annoyed to solve this problem


actually this is a basis about which we are running to a main project that we handle ..


so help us to rid of this problem


is it necessary to set the properties object in order to rid of this or if any additional code required please post them which will be helpful for us !!!!



- Sundarrajan.R








:confused::confused: