[java-list] Socket Cliente/Servidor

2003-02-19 Por tôpico juliojrl
Pessoal, preciso de um help para meu projeto, tenho que enviar mensagem ou arquivo do 
cliente para o servidor e vice-versa.
Alguém sabe me informar onde estou errando?
As classes Cliente e servidor estão em anexo.

Por favor estou preocupado, me ajudem!




Cliente.java
Description: Binary data


ServerS.java
Description: Binary data
-- LISTA SOUJAVA 
http://www.soujava.org.br  -  Sociedade de Usuários Java da Sucesu-SP
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED]
-


[java-list] Variável de ambiente

2003-02-14 Por tôpico juliojrl
Oi pessoal,

Preciso de um help por favor.
Uso em casa o JSDK no Linux ou no Win9x, mas no trabalho é NT e sei que não hà o 
autoexec.bat para alterar, como faço para setar as varáveis de ambiente para compilar 
no prompt do DOS direto da minha pasta de trabalho?


Um abraço, 
Julio Lima.








-- LISTA SOUJAVA 
http://www.soujava.org.br  -  Sociedade de Usuários Java da Sucesu-SP
dúvidas mais comuns: http://www.soujava.org.br/faq.htm
regras da lista: http://www.soujava.org.br/regras.htm
historico: http://www.mail-archive.com/java-list%40soujava.org.br
para sair da lista: envie email para [EMAIL PROTECTED]
-




[java-list] Erro Socket

2003-02-14 Por tôpico juliojrl
Pessoal,

Estou fazendo uma conexão entre cliente/servidor para enviar mensagem ou arquivo em 
ambos os sentidos. Alguém sabe me dizer onde estou errando?

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;

public class ServerS extends Thread{
   String Smsg;
   String msg;
   String inmsg;

   private ServerSocket serverSocket;


public ServerS(){

super(Servidor);
try{
serverSocket = new ServerSocket(6789);
System.out.println(Criei um Servidor...);

}
catch(IOException e){
System.err.println(Exception: couldn't create socket);
System.exit(1);
}
}

 public static void main (String args[ ] ) {

ServerS srv;
srv = new ServerS();
srv.start();

}
 public void run(){

Socket clientSocket = null;

while (true){

if (serverSocket == null)
  return;
  try{
 clientSocket = serverSocket.accept();

 }
   catch(IOException e){

   System.err.println(Exception: couldn't connect to client 
socket);
   System.exit(1);
   }


   // Recebe a mensagem via Socket do cliente

PrintWriter os;

try{
InputStreamReader inr = new 
InputStreamReader(clientSocket.getInputStream());
BufferedReader in = new BufferedReader(inr);
os = new PrintWriter(clientSocket.getOutputStream(),true);
while (  (inmsg = in.readLine( )) != null )
{

//Imprime a mensagem localmente
  System.out.println(inmsg);

}

} catch (IOException e) { System.err.println(e.toString( ));}

   // }

System.out.println(Entre com uma mensagem..);

 try {
 //Recebendo a mensagem via teclado a ser enviada ao Cliente


 DataInputStream msg;
 msg = new DataInputStream(System.in);
 Smsg = msg.readLine();
}catch (IOException i) {
   System.out.println(Erro !);
   }

 //Enviando a mensagem ao cliente...

try {

 PrintStream ps = new 
PrintStream(clientSocket.getOutputStream());
 ps.println(Smsg);

}
catch (IOException e)
  {
 System.out.println(Error:  + e);
  }
   }

 }
  }



// Cliente

import java.io.*;
import java.net.*;


class Cliente {
   String msg;
   private ServerSocket serverSocket;
   String line;
   static String Omsg;


public static void main (String args[ ] ) {

Cliente cli;
cli = new Cliente();

DataInputStream lemsg;
DataInputStream asg;
//DataInputStream msg;

lemsg = new DataInputStream(System.in);

// Abre o Socket

try{
Socket s = new Socket(Localhost,6789);



 // Escolhe a opção de digitar a mensagem ou ler um arquivo

System.out.println(Digite mm para mensagem ou aa para arquivo);

try {
DataInputStream msg;
asg = new DataInputStream(System.in);
cli.Omsg = asg.readLine();

 }catch (IOException i) {
 System.out.println(Erro !);

 }

 //Caso a opção seja digitar a mensagem..
String str1 = mm;
if (Omsg.equals (str1))
{

System.out.println(Entre com uma mensagem);

try {
 DataInputStream msg;
 msg = new DataInputStream(System.in);
 cli.msg = lemsg.readLine();
}catch (IOException i) {
   System.out.println(Erro !);
 }



// Enviando a mensagem ao Servidor...

try {

//Socket s = new Socket(Localhost,6789);
PrintStream out;
out = new PrintStream(s.getOutputStream( ));
out.println(cli.msg);
}
catch (IOException e)
  {
 System.out.println(Error:  + e);
  }
   }
// Caso a opção seja ler um arquivo..

String str2 = aa;
if (Omsg.equals (str2))
{

try {

 // Socket s = new