- Home /
I have .unity3d web on a Node.js server but the Unity3d app will not load. I believe it is a mime type restriction. Is there a Node.js function or plugin that can set up my mime types?
I cannot play my unity3d game files (mime type="application/vnd.unity") over a Node.js connection. (I am able to play the unity3d through the Apache Vhosts Access.) I just started a new instance of a Node.js app server to begin development of server side game components.
I have a basic server.js:
var http = require('http'),
fs = require('fs');
fs.readFile("./unityBase.html", function (err, html) {
if (err) {
throw err;
}
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(8080);
});
And a simple unityBase.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity Web Player | StarFluke</title>
</head>
<body>
<div id="unityPlayer"><embed src="build.unity3d" type="application/vnd.unity" width="960" height="600" firstframecallback="UnityObject2.instances[0].firstFrameCallback();" enabledebugging="0" style="display: block; width: 960px; height: 600px;">
</div>
</body>
(I stripped out a Style block for you to see the code easier.)
As I mentioned earlier, the unityBase.html runs fine in Apache Vhost Access; it does not run through a normal browser connection to www.starfluke.com or starfluke.com. It gives an error that claims the unity3d file is corrupt.
Do you have any suggestions of what I might try? Anything would be helpful, I am new at Node.js.
Oh, when testing the page make sure you have the Unity3D web player installed: (http://unity3d.com/webplayer). I stripped out that part of the page code to try to narrow down the problem.
Thank you, Daniel
Answer by StarFluke · Jul 02, 2014 at 06:59 AM
Solution! It was not a normal mime type problem. Node.JS needed to know the type of the unity3d file before serving it so the brute force and naive file read done in the server.js above was never going to work.
Using Node.js Express (or a number of other HTML server modules) is the quickest solution unless you really are tight on performance.
I am programming in Eclipse with NodeClipse and chose to go with a set of modules already supported by this plugin (e.g. {Express, ejs, LESS} one of nine supported combinations.) This is a great combo to host a Unity3D game on!
Daniel Game Daddy
Can you explain your answer in a little more detail please? I'm having a similar issue, it's saying the download failed. I've put my WebPlayer.html file and WebPlayer.unity3d file in a public directory so they're treated as static files and added this code to my app.js file:
app.use('/public', express.static(__dirname + '/public'));
express.static.mime.define({
'application/vnd.unity': ['unity3d'],
});
But I still cannot get it to work
Here's the link to my question: http://answers.unity3d.com/questions/788552/nodejs-with-unity.html
Your answer
Follow this Question
Related Questions
Error running WebGL on any browser 0 Answers
Web Player crashes (Invalid unity web file (decompression failure)) 1 Answer
What kind of error handling does the WWW class have? 1 Answer
What is an alternative to using System.IO Stream when building for webplayer ? 3 Answers
What "Invalid OpenGL Context for rendering" means? 0 Answers