it's possible using javascript socket client in unity js script..?


is the unity js script support for socket client using javascript ? or any something suggestion to use javascript socket client in unity?

i try library for javascript socket client but i don't know how to implement that in unity, any someone can explain that?

<script src="/"></script>
  var socket = io.connect('http://localhost');
  socket.on('news', function (data) {
    socket.emit('my other event', { my: 'data' });

this code in htm page, i think i have idea to include taht script in unity but i can't found documentation for that...thanks for helping

4/3/2012 3:35:49 AM

Accepted Answer

Unity's javascript is not real javascript. Unity's javascript is a different language called UnityScript, whose syntax is similar to original javascript.

UnityScript is based on Mono, a open source .Net framework implementation. so what you need is .Net socket, not

For example, to create a TCP client socket in C#:

TcpClient client = new TcpClient(server, port);
NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);

In UnityScript:

var client : TcpClient = new TcpClient(server, port);
var stream : NetworkStream = client.GetStream();
stream.Write(data, 0, data.Length);

Different syntax, but the same API/library.

11/12/2015 4:38:40 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow