Pessoal analise meu código, se alguém puder me dizer porque não consigo pegar o conteúdo do socket.
INICIANDO O SERVIDOR:
[code]public class IniciaServidor {
public static void main (String args[]){
Servidor srv = new Servidor();
srv.IniciaServidor();
}
}[/code]
SERVIDOR INICIADO:
[code]public class Servidor {
public void IniciaServidor(){
try {
ServerSocket srv = new ServerSocket(5555);
System.out.println("Servidor Aguardando cliente na porta 5555");
while (true){
Socket socket = srv.accept();
recebecliente receber = new recebecliente(socket);
new Thread (receber).start();
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
}
[/code]
THEAD PARA GERENCIAR CLIENTES:
[code]public class RecebeCliente implements Runnable{
private Socket socket;
public RecebeCliente(Socket socket) {
this.socket = socket;
}
public void run() {
try {
//ObjectInputStream entrada = new ObjectInputStream(socket.getInputStream());
DataInputStream in = new DataInputStream(socket.getInputStream());
System.out.println(socket.getInetAddress().getHostAddress());
String nome = in.readUTF();
System.out.println(nome);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
[/code]
CLASSE NO CLIENTE QUE CRIA O SOCKET E QUE ENVIA AO SERVIDOR:
[quote]package br.cliente;
import java.io.DataOutputStream;
import java.net.ConnectException;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JOptionPane;
/**
*
-
@author Vagner Duarte
*/
public class ClienteSocket {
private String ip;
private String nome;public ClienteSocket() {
}public ClienteSocket(String ip, String nome) {
this.ip = ip;
this.nome = nome;
}
public void conectanoservidor(){try { Socket cliente = new Socket(ip, 5555); DataOutputStream saida = new DataOutputStream(cliente.getOutputStream()); saida.writeBytes(nome); saida.flush(); saida.close(); cliente.close(); //System.out.println(ip); //System.out.println(nome); } catch (UnknownHostException ex) { ex.printStackTrace(); } catch (ConnectException erro) { JOptionPane.showMessageDialog(null, "Servidor não Localizado!"); } catch (Exception e){ e.printStackTrace(); }
}
}[/quote]