Gregorio
unread,May 17, 2013, 1:33:32 PM5/17/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to python...@googlegroups.com
Eai pessoal, tudo certo?
Bem, estou construindo um cliente de um chat para minha cadeira de Sistemas Distribuídos através de sockets.
Eis o problema: Em java conseguia definir o out como saída para o socket, assim quando em dava o System.out.print() ele jogava para o buffer do socket e não imprimia na tela, função que o servidor de chat fica responsável pro fazer:
exemplo \/
Socket s = new Socket(host, porta);
final BufferedReader in = new BufferedReader(
new InputStreamReader(
s.getInputStream()));
out = new PrintWriter(s.getOutputStream());
e aqui segue o resto da minha fonte, que faz uso deste recurso:
String nickname = null;
while(nickname == null || nickname.isEmpty()){
nickname = JOptionPane.showInputDialog("Digite seu nickname");
}
enviarParaServidor(nickname);
Thread t = new Thread() {
@Override
public void run() {
int tempoAux = 0;
while (tempoAux < tempoPing) {
enviarParaServidor("/ping");
}
}
};
t.start();
Thread tPing = new Thread() {
@Override
public void run() {
String txt = null;
try {
while ((txt = in.readLine()) != null) {
tela.getTxtMensagens().setText(tela.getTxtMensagens().getText().concat(txt));
}
} catch (SocketException e) {
System.out.println("Fim da execucao!");
}catch(IOException io){
io.printStackTrace();
}
}
};
tPing.start();
// String linha = null;
// while(!(linha = teclado.nextLine()).equals("sair")){
// out.println(linha);
// out.flush();
// }
//s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void enviarParaServidor(String msg){
out.println(msg);
out.flush();
}
public static void enviarMensagem(){
enviarParaServidor(tela.getTxtEntrada().getText());
tela.getTxtEntrada().setText("");
tela.getTxtEntrada().requestFocus();
}
private void atualizaLista(){
out.println("/lista");
}
Estou bem perdido de como posso fazer isso em python, alguém pode me ajudar?
Obrigado!