Pregunta

Soy nuevo en .net remoting, hice algunas aplicaciones de muestra en .net remoting.i fácilmente obtener un archivo desde el servidor a través del objeto remoto, pero no sé cómo enviar un archivo al servidor, si es posible a través de una interfaz significa cómo diseñarlo. Dame algunas sugerencias y enlaces, será útil para mí conducir en la dirección correcta

¿Fue útil?

Solución

Para enviar un archivo, puede llamar repetidamente un método en el servidor para darle el fragmento de archivo por trozo. Así:

static int CHUNK_SIZE = 4096;

// open the file
FileStream stream = File.OpenRead("path\to\file");

// send by chunks
byte[] data = new byte[CHUNK_SIZE];
int numBytesRead = CHUNK_SIZE;
while ((numBytesRead = stream.Read(data, 0, CHUNK_SIZE)) > 0)
{
    // resize the array if we read less than requested
    if (numBytesRead < CHUNK_SIZE)
        Array.Resize(data, numBytesRead);

    // pass the chunk to the server
    server.GiveNextChunk(data);
    // re-init the array so it's back to the original size and cleared out.
    data = new byte[CHUNK_SIZE];
}

// an example of how to let the server know the file is done so it can close
// the receiving stream on its end.
server.GiveNextChunk(null);

// close our stream too
stream.Close();

Otros consejos

Debes implementar este comportamiento. El cliente lee el archivo y envía los bytes. El servidor recibe los bytes y escribe el archivo. Hay más en eso, pero eso es lo básico de lo que tendrá que hacer.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top