Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
java socket messeging in a network

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);
        }
    }
}

}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!