Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
Sending data to and receiving data from localhost in Unity caused "IOException: Too many open files" error

To test the networking part of my Unity application, I have an "imitatee" game object that moves according to the keyboard input. The networking manager component (1) gets the movement data of the "imitatee" and sends it to a node.js localhost server using PUT and also (2) gets back the from localhost and applies it to the "imitator" object. The program worked fine, but after a while I got the error:

IOException: Too many open files

A window also popped up in the Unity editor saying that "Opening files failed" and then the editor crashed. I think that it was caused by memory not being disposed properly but have not figured out exactly how. Here is the GameManager code:

NetworkingManager.cs

public class Data
{
    public float posX;
    ...

    public Data(float posX...)
    {
        this.posX = posX;
        ...
    }
}

public class NetworkingManager : MonoBehaviour
{

    private GameObject imitator;
    private GameObject imitatee;

    private Data data;
    private string jsonData;
    private Data receivedData;

    private string uri = "http://localhost:3000/";

    private void Awake()
    {
        // Assign references
        ...
    }

    private IEnumerator SendData()
    {
        data = new Data(
            imitatee.transform.position.x,
            ...
            );

        jsonData = JsonUtility.ToJson(data);

        using (UnityWebRequest req = UnityWebRequest.Put(uri, jsonData))
        {
            req.SetRequestHeader("Content-Type", "application/json");
            yield return req.SendWebRequest();
    

            if (req.isNetworkError || req.isHttpError)
            {
                Debug.Log(req.error);
            }
        }

    }

    private IEnumerator ReceiveData()
    {

        using (UnityWebRequest req = UnityWebRequest.Get(uri))
        {
            yield return req.SendWebRequest();

            if (req.isNetworkError)
            {
                Debug.Log(req.error);
            }
            else
            {
                receivedData = JsonUtility.FromJson<Data>(req.downloadHandler.text);

                imitator.transform.position = new Vector3(
                    receivedData.posX,
                    ...
                    );

                ...
            }
        }
        
    }

    void Update()
    {
        StartCoroutine(SendData());
        StartCoroutine(ReceiveData());
    }
}

Besides, there was no error logged for the node.js backend.

backend.js

const express = require('express')
const app = express()
app.use(express.json())
const port = 3000
var data

app.get('/', (req, res) => {
  if (data) res.json(data)
})

app.put('/', (req, res) => {
  data = req.body
  console.log("Received " + req.body) 
})

app.listen(port, () => {
  console.log(`App listening at http://localhost:${port}`)
})

Appreciate your help!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!