Hello everyone, I am trying to make a chat application. For this i have made two programs-SERVER and CLIENT.
But these are connecting.
import java.io.*;
import java.net.*;
public class SimpleServer
{
public static void main(String args[])
{
ServerSocket s=null;
try
{
s=new ServerSocket (6666);
}
catch(IOException e)
{
e.printStackTrace();
}
while(true)
{
try
{
Socket s1=s.accept();
OutputStream s1out=s1.getOutputStream();
BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(s1out));
bw.write("hello");
bw.close();
s1.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}
}
and Client.java
import java.net.*;
import java.io.*;
public class SimpleClient
{
public static void main(String args[])
{
try
{
Socket s1=new Socket("171.76.149.182",6666);
InputStream is=s1.getInputStream();
DataInputStream dis=new DataInputStream(is);
System.out.println(dis.readUTF());
// br.close();
s1.close();
}
catch(ConnectException connExc)
{
System.err.println("could not connect");
}
catch(IOException ex)
{
ex.printStackTrace();
}
{
}
}
}
I am getting the following error:
run:
java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readUTF(DataInputStream.java:592)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
at SimpleClient.main(SimpleClient.java:12)
BUILD SUCCESSFUL (total time: 0 seconds)
Can anyone please give me their suggestions . Thanks in advance.