I am trying to make communication between A simple Servlet deployed in Java web application and the demo html file provided in easyRTC which has video+audio enabled. I pass one parameter from Java application to NodeJS as HttpRequest and using that parameter I can communicate over video+audio between nodeJS application and my Java Application.
My Servlet Code:
URL url = new URL("http://localhost:3000/demos/read_post_audio_video.html");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
String urlParameters = "id=" + URLEncoder.encode("123456", "UTF-8");
DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
wr.writeBytes (urlParameters);
wr.flush ();
wr.close ();
if(connection.getResponseCode() == 200){
InputStream is = connection.getInputStream();
copyStream(is, response.getOutputStream());
}
I have copyStream as:
public static void copyStream(InputStream input, OutputStream output)
throws IOException
{
byte[] buffer = new byte[1024]; // Adjust if you want
int bytesRead;
while ((bytesRead = input.read(buffer)) != -1)
{
output.write(buffer, 0, bytesRead);
}
}
On NodeJS (easyRTC) Server side, I am trying to get the data from received POST request. and display it on html page. NodeJS is running on port 3000.
var express = require('./node_modules/express');
var app = express.createServer();
app.use (function(req, res, next) {
var data='';
req.setEncoding('utf8');
req.on('data', function(chunk) {
data += chunk;
});
req.on('end', function() {
req.body = data;
next();
});
});
app.post('/', function(req, res)
{
console.log(req.body);
});
app.listen(3000);
Here I want to pass the urlParameters that is id to NodeJS url, and display the received id onto the html page. Once this ID is received at NodeJS Server side, I want to make communication between them for easyrtc video+audio.