Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda