Well, I am facing problems trying to implement this.
What I had in mind was communication in an ad-hoc network created between the laptops.
Initially, i tried broadcasting over my machine (under 127.0.0.1) and it worked fine.
But then, i try to do it between two machines connected through an ad-hoc wi-fi network, the server and the client are apparrantly connected, and after a while, because of the default time, a message appears on both sides saying the network has timed out.
The code for the client is:
- import java.io.*;
-
import java.net.*;
-
class clientt
-
{
-
public static void main(String args[]) throws SocketException,IOException
-
{
-
Socket s=new Socket("169.254.46.123",12345);
-
PrintStream ps=new PrintStream(s.getOutputStream());
-
ps.println("Hello from client side");
-
DataInputStream dis=new DataInputStream(s.getInputStream());
-
System.out.println(dis.readLine());
-
ps.close();
-
}
-
}
The code for the server is :
-
import java.io.*;
-
import java.net.*;
-
class servert
-
{
-
public static void main(String args[])throws SocketException,IOException
-
{
-
ServerSocket ss=new ServerSocket(12345);
-
Socket s=ss.accept();
-
DataInputStream dis=new DataInputStream(s.getInputStream());
-
System.out.println(dis.readLine());
-
PrintStream ps=new PrintStream(s.getOutputStream());
-
ps.println("Hello from server side");
-
ps.close();
-
}
-
}
Need some help here.