I am playing around with Android Sockets and I currently I am trying to send a file via WiFi. I have a simple protocol that uses few notification classes. Everything works OK on Java client and Java server, but I want to do the same thing with C# (or C++) server/client and Java client/server. I need to decide how to serialize my notification data.
I was thinking about XML format. It would contain a notification ID, client ID and some data (i.ex. chunk of a file).
How can I save a chunk of a file (or any byte array) into a XML file (or text based file)?
Maybe I am thinking completely wrong way?
Run your data through a Base64 encoder and then stick that data into a CDATA section in your xml file. Apache makes a Base64 library for Java. I'm sure it wouldn't be too hard to find one for C#/C++.
Related
Hi and thanks in advance,
So I have a program which already creates a socket and can send strings both ways between the server and client using UDP.
However, I need to ask something before I continue with trying to send a file (specifically a text file) over my connection.
Is there a way to physically send an actual file over the connection as apposed to simply sending the files contents, or does sending it contents count as sending the files itself?
I just want to make sure on this before I continue with my program.
Thank you.
A file is not a physical object. It is more an idea of interpreting your disks magnetical (or electrical) state.
A "file" is mainly its content. There is some additional information like permissions, owner, last edit date and so on. But I assume that you don't want to send these information.
I have no idea what the specific goal is you are trying to achieve but it is safe to say, that for most applications it is perfectly fine to think of the contents of a file when saying "file".
I explain, I tried to open my database .sqlite contained in my server in Java with jdbc:sqlite:mydb, but it doesn't work because my database ".sqlite" is distant so i creat a script php based on my server which gets back me all of my databases.
So my question How can i Get back source data of data contained in a script PHP with Java?
Thanks a lot!
PS : Sorry for my english (I'm french)
One way would be to create a service in PHP which offers the data, so that your Java application can consume it.
E.g. PHP can expose the data in an XML or JSON format, for instance over HTTP. Your Java application would then call the HTTP URL and receive the data in JSON/XML/whatever, and then parse it to extract the data from that format.
There are other ways as well, e.g. a service bus could broker the data between the different systems, but that requires much more setup (though in the long run, it does have value, if you keep adding data that you want to expose to more and more systems).
You can create PHP WebService server and write some functions to operate that databases data for fixing your problems. Then just use Java to connect with soap to your created WebService functions.
How to start webservice, try to read this one:
http://greatgandhi.wordpress.com/2009/11/25/create-a-php-webservice-in-5min-using-php-soap-and-wsdl-technology-nusoap/
Its the best way i know, if you need to send some data back to your remote db. Its a little more complicated, but much more correct way to operate remote data.
I have a Java client/server desktop application, where the communication between client and server is based on Sockets, and the messages exchanged between client and server are serialized objects (message objects, that incapsulate requests and responses).
Now I need to make the client able to upload a file from the local computer to the server, but I can't send the File through the buffer, since the Buffer is already used for exchanging the message objects.
Should i open another stream to send the file, or is there any better way to upload a file for my situation?
I need to make the client able to upload a file from the local computer to the server
- Open a Solely Dedicated Connection to the Server for File uploading.
- Use File Transfer Protocol to ease your work, and moreover its quite easy and reliable to use the Apache's common lib for File uploading and downloading....
See this link:
http://commons.apache.org/net/
You really only have two options:
Open another connection dedicated to the file upload and send it through that.
Make a message object representing bits of a file being uploaded, and send the file in chunks via these message objects.
The former seems simpler & cleaner to me, requiring less overhead and less complicated code.
You can keep your solution and pass the file content as an object, for example as a String - use Base64 encoding (or similar) of the content if it contains troublesome characters
My android app was able to generate text files with key value pairs. Now, I want to upload those data to an online MySQL Database.
My Idea is, my App will communicate with a PHP file and so this PHP file will parse the text file and then insert it to MySQL database.
My question is, how will android upload and communicate with the PHP file? Any codes and other ideas out there?
You use these classes.
For examples on how to use them, SO is full of related question. Just search for "android http request".
Two things, first don't use a text file, just send the key value pairs in a HTTP post request, second remember to do all http requests asynchronously, you can use for example AsyncTask to do this.
i'm decoding and encoding a videofile via Xuggle to FLV-video format and send it via Sockets to my java server (not the entire file, only parts of it every X seconds). On the server-side I get the encoded file as ByteArrayInputStream. Is it possible to stream this ByteArrayInputStream via rtp or http-streaming? Or do i need a finished encoded file for that? I'm creating a video streaming server, where the client encodes the video file and sends it to the server in parts. This is already done. I'm now stuck on the server side, to stream the ByteArrayInputStream via RTP or HTTP, so I can watch it via VLC. Are there any good examples for it?
I've already tested to save the ByteArrayInputStream to file. This works but I don't wanna save the file on the server. I wanna stream it ;)
Thank you
1) See Server implementation
http://cs.anu.edu.au/student/comp3310/2004/Labs/lab6/lab5.html
2) http://code.google.com/p/vlcj/ and see http://code.google.com/p/vlcj/wiki/Streaming