Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not connecting to remote server! #51

Closed
Abdallah-Alwarawreh opened this issue Mar 28, 2023 · 9 comments
Closed

Not connecting to remote server! #51

Abdallah-Alwarawreh opened this issue Mar 28, 2023 · 9 comments

Comments

@Abdallah-Alwarawreh
Copy link

Abdallah-Alwarawreh commented Mar 28, 2023

when i connect to localhost with unity it works fine, but when I upload it to my remote server it doesn't work it returns unable to connect to remote server, but when I try to connect with this site "http://amritb.github.io/socketio-client-tool/", it works just fine

app.ts:

import { SocketServer } from "./Classes/Server";
import { WebServer } from "./Web/WebServer";
import express, { Express, Request, Response } from 'express';
const PORT = process.env.PORT || 8080;
// const PORT = 8080;

const http = require('http');
const app: Express = express();
const server = http.createServer(app);

var GameServer = new SocketServer(server);
var AdminServer = new WebServer(app);

server.listen(PORT, () => {
    console.log(`Server listening on port ${PORT}`);
});

server.ts

constructor(server: http.Server) {
        this.io = new Server(server, {
            cors: {
                origin: "*"
            }
        });
        
        this.DatabaseHandler = new DatabaseHandler();
        this.Connections = [];
        this.Lobbies = [];

        this.io.use(async (socket: Socket, next: any) => {
            console.log("Hit!");
            .......
        });
}
@itisnajim
Copy link
Owner

unity version, platform or the device, maybe a log or c# snippet code to have an idea!

@Abdallah-Alwarawreh
Copy link
Author

2021.3.19f1, unity editor on windows (android platform), the log just says unable to connect to remote server

socket = new SocketIOUnity(uri, new SocketIOOptions {
    Query = new Dictionary<string, string>
		{
			{"id", EncryptedId},
			{"username", EncryptedUsername},
			{"avatarURL", EncryptedAvatarURL},
		}
	,
	EIO = 4,
	Transport = SocketIOClient.Transport.TransportProtocol.WebSocket,
});

@itisnajim
Copy link
Owner

make sure the internet permission is enabled in the manifest (maybe its the cause)

<manifest xlmns:android...>
 ...
 <uses-permission android:name="android.permission.INTERNET" />
 <application ...> ... </application>
</manifest>

do the things in this comment:
#45 (comment)
try this if fixed ur problem.

@Abdallah-Alwarawreh
Copy link
Author

make sure the internet permission is enabled in the manifest (maybe its the cause)

<manifest xlmns:android...>
 ...
 <uses-permission android:name="android.permission.INTERNET" />
 <application ...> ... </application>
</manifest>

do the things in this comment: #45 (comment) try this if fixed ur problem.

I'm testing in unity editor, it it doesn't work, but it is working on localhost, just the remote server that is not working

@itisnajim
Copy link
Owner

make sure the internet permission is enabled in the manifest (maybe its the cause)

<manifest xlmns:android...>
 ...
 <uses-permission android:name="android.permission.INTERNET" />
 <application ...> ... </application>
</manifest>

do the things in this comment: #45 (comment) try this if fixed ur problem.

I'm testing in unity editor, it it doesn't work, but it is working on localhost, just the remote server that is not working

so maybe the remote server has kinda of security or not a valid version of socketio! and from the code you posted i don't see the import of socketio
const socket = require('socket.io');

like in the example:
https://github.com/itisnajim/SocketIOUnity/blob/main/Samples~/Server/index.js

@Abdallah-Alwarawreh
Copy link
Author

nah, it is imported i just put the important part of the ts code, btw I'm using typescript

import { Connection } from "./Connection";
import { Server, Socket } from "socket.io";
import { Lobby } from "./Lobbies/Lobby";
import { DatabaseHandler } from "./MySqlConn";
import { Player } from "./DataTypes/Player";
import { MatchMakingConnection } from "./MatchMakingConnection";
const { Encrypt, Decrypt } = require('./Encryption/EncryptionManager');
const { v4: uuidv4, v4 } = require('uuid');
import * as http from "http"

@Abdallah-Alwarawreh
Copy link
Author

Btw this is my package.json

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "run": "node dist/app.js",
    "build": "tsc -p tsconfig.json"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "crypto": "^1.0.1",
    "ejs": "^3.1.8",
    "express": "^4.18.2",
    "mysql": "^2.18.1",
    "nodemon": "^2.0.20",
    "socket.io": "^4.5.4",
    "uuid": "^9.0.0"
  },
  "devDependencies": {
    "@types/express": "^4.17.15",
    "@types/mysql": "^2.15.21",
    "@types/node": "^18.11.18",
    "@types/socket.io": "^3.0.2",
    "tsc": "^2.0.4"
  }
}

@Abdallah-Alwarawreh
Copy link
Author

Hi, i stopped it from reconnecting only connecting and I don't get anything back no OnConnected or OnError

@Abdallah-Alwarawreh
Copy link
Author

Fixed the issue!

just changed to port from 80 to 3001 and it worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants