• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need help on Java.NIO

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an application and need help and suggestions.

- First my application take any file name
(like image file or audio file or video file or any other extension files)
and Encode the file using Base64Encoder.

- Secondly, the contains of Encoded file will be stored in String and then it is passed to the xml.

- Thirdly It is starting a client (Client socket) and connecting to the server which is running on remote Unix machine.

- Fourth - It send's the XML File to the Server Socket.

- At ServerSocket,

First - It recieves the xml files and save it in TEMP folder.

Secondly - Another parsing method is called on xml file and it parse the XML file using DOM Parser.

Thirdly, New Encoded file is created in TEMP folder.

Fourth - Decoder is called and it will decode the file and retain back the original file at Server Location.

Above mention activities are working perfectly fine but the problem is :

I'm not able to send file which is more then 275KB.
where I want to send file upto the size in MB's. like 1 MB or 2MB etc.??

So, I wanted to try with NIO SocketChannel and ServerSocketChannel?

so does this help me send the file of Huge data???

If so, can any one could send me example application for communicating using JAVA.NIO (client and server).
Because I tried and I'm not able to understand this concept specially, Selectors, Channels, Blocking, NON Blocking etc.

so your guide in this matter will be highly appreciated as I'm very new in JAVA.NIO's

Please help.
Thanks
Mohammed Zubedi
mohammed.zubedi@xius-bcgi.com
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mohammed zubedi:

I'm not able to send file which is more then 275KB.



That should not happen. Can you show us a small snippet of code that exhibits this behavior?
 
mohammed zubedi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here is snippet from my WebApplication

1) String xmldata = con.GenerateXML(filename, data);

Below is GenerateXML method where im passing original file name and data and it returns me the XMLDATA.


public static String GenerateXML(String filename, String data)
{
String name = filename;
String encodedata = data;
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?<book><man><name>"+name+"</name><first>"+encodedata+"</first></man></book>";
return xml;
}

2) Then I'm sending XML

public static void sendRequest(String ip, int port, String xmlrequest) throws Exception
{

Socket sock = null;
try {
sock = new Socket(ip,port);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())), true);
out.println(xmlrequest);

}

catch(Exception e)
{
System.out.println("Exception thrown in socket ");
}
//return xmlrequest;

}

}

Note : all other logic like Encoding, Decoding, Parsing are done in other methods, but every thing is working perfectly fine but when I'm trying to send data which is of high KB ..its' getting stuck.

Please help.
Thanks
Mohammed.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you invoking flush() or close() anywhere?
If you don't there's a good possibility that data is getting cached somewhere and not being sent.
 
mohammed zubedi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I'm invoking flush() for closing out object of PrintWriter.
ie out.flush();

But I'm not able to find out the cause for not able to send data which is more then 275-300 KB.

Any suggestions or different ways to solve this issue?
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mohammed zubedi:
Yes I'm invoking flush() for closing out object of PrintWriter.
ie out.flush();



Where are you invoking it? Are you expecting to receive data on your server before flush() or close() is invoked?
Did you write the server? The problem may be on that end.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic