All pastes #165255 Raw Edit

Stuff

public java v1 · immutable
·published 2006-09-09 17:57 UTC
rendered paste body
package protocoloReqResp;import java.io.*;import java.net.*;public class ServerCommModule {	public static byte[] getRequest() {		final int PORT_NUM = 4242;		String answer = "";		try {			ServerSocket listenSocket = new ServerSocket(PORT_NUM);			Socket clientSocket = listenSocket.accept();			ObjectInputStream in = new ObjectInputStream(clientSocket					.getInputStream());			Message data = (Message) in.readObject();			String[] aux = new String(data.getArguments()).split(" ");			int count = 0;			switch (data.getMethodID()) {			  case 1:				for (int i = 0; i < aux.length; i++)					count = count + Integer.parseInt(aux[i]);				break;			  case 2:				for (int i = 0; i < aux.length; i++)					count = count - Integer.parseInt(aux[i]);				break;			  default:				for (int i = 0; i < aux.length; i++)					count = count * Integer.parseInt(aux[i]);				break;			}			answer = data.getMethodID() + '#'					+ clientSocket.getInetAddress().toString() + '#'					+ clientSocket.getPort() + '#' + "Resultado: " + count;		} catch (IOException e) {			System.out.println("Listen :" + e.getMessage());		} catch (ClassNotFoundException e) {			e.printStackTrace();		}		return answer.getBytes();	}	public static void sendReply(byte[] reply, InetAddress clientHost,			int clientPort) {	}}