Strumenti Utente

Strumenti Sito


lpr-b:remotestream
package nfs;
 
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
 
public class RemoteStream {
	final int MAX = 4096;
	String serverName = null; // name of the remote server
	String filename = null;   // name of the remote file
	DatagramSocket ds = null; // the socket used to send data
	InetAddress serverAddress = null;
	String handle = null;
 
	public RemoteStream(String serverName) {
		this.serverName = serverName;
	}
 
	public boolean open(String filename) {
		UDPServerComm comm = new UDPServerComm(serverName, NfsServer.port);
		DatagramPacket dp = RemotePacket.RemotePacket("OPEN",filename);
		// packet received: contains the String remote handle
		DatagramPacket answer = comm.call(dp);
		if(answer == null) 
			return false; // error receiving
		RemotePacket rp = new RemotePacket(answer);
		if(rp.getOp().equals("ERROR")) {
			System.out.println(rp);
			return false;
		}
		// memorizza handle
		if(rp.getOp().equals("HANDLE")) {
			handle = rp.getArgs()[0];
			return true;
		}
		// per default return false
		return false;
	}
 
 
 
	public boolean close() {
		UDPServerComm comm = new UDPServerComm(serverName, NfsServer.port);
		DatagramPacket dp = RemotePacket.RemotePacket("CLOSE",handle);
		// packet received: contains the String remote handle
		DatagramPacket answer = comm.call(dp);
		if(answer == null) 
			return false; // error receiving
		RemotePacket rp = new RemotePacket(answer);
		if(rp.getOp().equals("ERROR")) {
			//System.out.println(rp);
			return false;
		}
		return true;
	}
 
}
lpr-b/remotestream.txt · Ultima modifica: 19/11/2007 alle 15:13 (12 anni fa) da Sonia Campa