Error in string conversion is happening in the Unity web server

I am attempting to create a web socket server using typescript and integrate it with Unity (client). However, I am encountering a string conversion error when trying to communicate with Unity. Interestingly, my friends used the same socket server code in their Unity projects without any errors. Curiously, when I tested my client code with another project, the same error persisted. Although I use Korean as my computer language, there are no Korean characters in my project directory.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Net.WebSockets;
using System;
using System.Threading;

public class SocketManager : MonoBehaviour
{
    private ClientWebSocket _socket = null;

    private void Start()
    {
        Connection();
    }

    public async void Connection()
    {
        Debug.Log("Starting Connection");
        if (_socket != null && _socket.State == WebSocketState.Open)
        {
            Debug.Log("Socket already connected");
            return;
        }

        _socket = new ClientWebSocket();
        Uri serverUri = new Uri("ws://localhost:50000");

        await _socket.ConnectAsync(serverUri, CancellationToken.None);

        Debug.Log("Connected");

        ArraySegment<byte> bufferSegment = new ArraySegment<byte>(new byte[1024]);
        WebSocketReceiveResult result = await _socket.ReceiveAsync(bufferSegment, CancellationToken.None);

        string msg = System.Text.Encoding.UTF8.GetString(bufferSegment.Array);
        Debug.Log(msg);
    }

    private void OnDestroy()
    {
        Disconnect();
    }

    public void Disconnect()
    {
        if (_socket != null)
        {
            _socket.CloseAsync(WebSocketCloseStatus.NormalClosure,
                               "Quit",
                               CancellationToken.None);
        }
    }
}

My WS server code:

import Express, { Application } from 'express';
import {IncomingMessage} from 'http'
import WS from 'ws';

const App: Application = Express();

const httpServer = App.listen(50000, () =>{
    console.log("Server is running on 50000 port");
});

const socketServer : WS.Server = new WS.Server({
    server:httpServer,
    //port:9090
}, () => {
    console.log("Socket server is running on 50000 port");
});

socketServer.on("connection", (soc:WS, req:IncomingMessage) => {
    payload: Uint8Array = new Uint8Array(20);
    soc.send("Welcome to My Server!");
});

The Error

ExecutionEngineException: String conversion error: Illegal byte sequence encounted in the input. System.Net.Dns.GetHostByName (System.String hostName) (at :0) System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) (at :0) System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) (at :0) (wrapper delegate-end-invoke) .end_invoke_IPAddress[]__this___IAsyncResult(System.IAsyncResult) System.Net.Dns.EndGetHostAddresses (System.IAsyncResult asyncResult) (at :0) System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction, System.Threading.Tasks.Task`1[TResult] promise, System.Boolean requiresSynchronization) (at :0) End of stack trace from previous location where exception was thrown ---

Answer №1

Have you ever encountered a double byte character in your computer's name? There was a post I came across discussing a similar issue:

It seems like the problem arises during DNS lookup. Perhaps changing your computer's name could resolve the issue. You might also want to check if your friend's computer has any double byte characters in its name – my guess is they don't?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I accurately determine the parameters of an ellipse that represents the trajectory of an object in space using initial condition values (r0, v0, deltat, and mu)?

In my current game project, I'm developing a primary user interface that displays the solar system from a top-down perspective (with Earth's north pole as 'up'). One of the challenges I faced was creating a semi-realistic path for an ob ...

There are no files available for the remoteEntry chunk at this time

My webpack.config.json file includes the following module federation configuration: new ModuleFederationPlugin({ name: 'my-app', filename: 'remoteEntry.js', exposes: { './MyApp': './src/app/App.t ...

How to trigger a click event in React using TypeScript and material-ui library

Currently, I am facing an issue when trying to update the value of material-ui TextFields from the store. When manually typing inside the field, everything works fine as expected with the handleChange() and handleBlur() functions handling the events. Howev ...

"Troubleshoot: Issue with React class component's setState not correctly updating

Hey there! I could really use some help with the issue I'm facing: So, I have a React class component that extends React.Component and it has a method that allows me to set its state whenever I want. I understand that passing a prop to the component ...

Tips for keeping a React-Table row expanded during re-render processes

I am working on a straightforward react-table that includes an expanded sub-component linked to a Redux state object. Whenever the sub-component is expanded, I make an API call to retrieve additional data for lazy-loading into the Redux store. The Redux s ...

Issue with typescript in Material-UI Next

I encountered an error while trying to integrate material-ui-next component into a default VS2017 react-redux template. The error message reads as follows: ERROR in [at-loader] ./node_modules/material-ui/BottomNavigation/BottomNavigationButton.d.ts:6:74 T ...

Creating a rootscope variable within an .ASPX file

I'm currently facing a challenge of defining an AngularJS rootscope variable within an .ASPX file for utilization in a TypeScript file. However, I'm not entirely sure on the best approach to achieve this. I am willing to explore any viable method ...

Display a loading spinner while the search bar makes an API request in Angular

I'm struggling with incorporating a loading spinner display when a user enters a search term in the search bar. When there is a change detected in the search term property, an API request is made to populate the lists in the view with the relevant dat ...

When running `ng serve` or `ng build --prod`, the dist folder is not created in an Angular 4 application

I recently completed building an Angular 4 app using angular-cli version 1.0.4 and generated the production build with the command ng build --prod. However, I encountered a problem as the expected dist folder was not created after executing this command. ...

When executing the command node server.js, an error is thrown stating: "Route.post() is expecting a callback function, however, it received an object of type Undefined at Route.<computed

As the title suggests, I am creating a boilerplate for use in multiple projects. Everything seems fine from a syntax perspective, but when I try to run 'node Server.js', this is the error that occurs: Node.js v20.11.0 PS C:\Users\Edward ...

"What could be causing my React application to enter a never-ending re-rendering cycle when I incorporate

Currently, I'm working on a code to update the content of a previous post with image URLs received from the server. However, I'm facing issues with excessive re-renders due to my coding approach. Specifically, when converting the image URLs into ...

The TypeScript declaration for `gapi.client.storage` is being overlooked

When I call gapi.client.storage.buckets.list(), TypeScript gives me an error saying "Property 'storage' does not exist on type 'typeof client'." This issue is occurring within a Vue.js application where I am utilizing the GAPI library. ...

What is the best way to provide transformers in ts-node?

Currently, I am in the process of creating my own compiler for Typescript because I require the usage of transformers. Within our workflow, we utilize ts-node to execute specific files (such as individual tests), and it is essential that these transformer ...

Utilizing TypeScript's dynamic class method parameters

I've been working on integrating EventBus with TypeScript and I'm trying to create a dynamic parameter event in the emit method. How can I achieve this? interface IEventBusListener { (...params: any[]): void } class EventBus { constructo ...

Can someone please help me configure typescript, webpack, and vuejs to locate packages in my node_modules/older/lib/ directory?

I'm in the process of converting an older typescript project into a library for a new vue.js project. The previous package is set up to output to ./lib/ using tsconfig.json, and all the necessary "this is where my library is" configurations are includ ...

Enhanced TypeScript declarations for a node package that expands upon default TypeScript typings

I'm currently working on creating comprehensive typings for the https://www.npmjs.com/package/keypress npm package. While I have successfully typed out the basic function, I am facing challenges in extending the declaration of process.stdin to align ...

What is the process for re-exporting global.d.ts typings in a third-party JavaScript project?

Despite being able to create typings enabling my typescript modules to use function definitions from a third-party javascript module, this approach seems to cause issues for packages importing my module. To address this concern, I included the necessary t ...

Utilize devextreme for uploading files

Currently, I am trying to implement an upload document feature using Dev-Extreme, but I keep encountering an error https://i.sstatic.net/dLxWx.png onFileUpload(event){ this.file = event.target.files[0] } <dxi-column [showInColumnChooser]="fa ...

Using Typescript to specify the type of data returned from a POST request

In my code, I am making a post request using got in the following way: const got = got_.extend({ prefixUrl: serviceUrl, responseType: 'json' }) const { body } = await got.post('newAddress', { json: { userId } }) The conten ...

Move on to the following iteration within a (Typescript) .forEach loop by using setTimeout

Within my array, I have a list of image URLs that I need to update the src attribute of an img tag every 10 seconds. To achieve this, I am using a forEach loop which includes a setTimeout function that calls a DOM manipulation function (replaceImage) as sh ...