this is the code which runs server in a thread infinitely and client for three times, this code works fine when i connect two laps in my mobile hot spot but then when i try to connect to my college WiFi(larger network)it is not working so what should i do to get it right when i connect to college network
thanks in advance :)
import java.io.*;
import java.net.*;
import java.util.*;
public class MyServer
{
public static void main(String[] args)
{
new thser();
for (int i=0;i<3;i++ )
{
try
{
Scanner in=new Scanner(System.in);
String mys=in.nextLine();
Socket s=new Socket("112.168.43.134",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF(mys);
dout.flush();
dout.close();
s.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}
class thser extends Thread
{
public thser()
{
start();
}
public void run()
{
while(true)
{
try
{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}
Not sure if i understood the question right, but this is my answer: Larger networks, who can be vulnerable to inside attacks, usually routes their connections so that two devices on their network cant speak directly to each other. This is the case at my school, witch makes me unable to host local servers on the network. This might be the problem in your case. The router in your collage may not permit your pc to send packets to any local ip on the network.
I think that this is most likely the problem. You can test this simply by trying to ping your phone or something, when both are on the collage network.
The program worked great on my computer :)
PS: Hope you remembered to change the ip on line 15, when you changed from your hotspot wifi to your collage wifi