Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Socket AS3 ( Receive File .TXT ) + Java Socket

New Here ,
Apr 07, 2015 Apr 07, 2015

Hi,

I have Java Socket sending .TXT file ( 10 MB ) . But the AS3 only gets 63 Kb . I do not understand the loss of bytes ...

Souce Java :

public void sendFile(String fileName) {

        try {

            //handle file read

            File myFile = new File(fileName);

            byte[] mybytearray = new byte[(int) myFile.length()];

            FileInputStream fis = new FileInputStream(myFile);

            BufferedInputStream bis = new BufferedInputStream(fis);

            DataInputStream dis = new DataInputStream(bis);

            dis.readFully(mybytearray, 0, mybytearray.length);

            OutputStream os = clientSocket.getOutputStream();

            byte[] fileSize = intToByte(mybytearray.length);

            byte[] clientData = new byte[(int) myFile.length() + mybytearray.length];

            System.arraycopy(fileSize, 0, clientData, 0, fileSize.length); // Copy to the file size byte array to the sending array (clientData) beginning the in the 0 index

            System.arraycopy(mybytearray, 0, clientData, 4, mybytearray.length); // Copy to the file data byte array to the sending array (clientData) beginning the in the 4 index

            DataOutputStream dos = new DataOutputStream(os);

            //dos.writeUTF(myFile.getName());

            //dos.writeInt(mybytearray.length);

            dos.write(clientData, 0, clientData.length);

            dos.flush();

}

AS3 Source..

private function onResponse(e:ProgressEvent):void {

  var file:File;

  var fs:FileStream;

  var fileData:ByteArray = new ByteArray();

  file = File.documentsDirectory.resolvePath("tmpReceive.txt");

  fs = new FileStream();

  fs.addEventListener(Event.CLOSE,onCloseFileReceive);

if(_socket.bytesAvailable > 0) {

  while(_socket.bytesAvailable) {

  // read the socket data into the fileData

  _socket.readBytes(fileData,0,0);

  }

  }

  fs.open(file, FileMode.WRITE);

  // Writing the file

  fs.writeBytes(fileData);

  fs.close();

TOPICS
ActionScript
271
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation