Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda