Hello,
I am having a really strange problem with TcpClient / Listener. To put it briefly, the code has been working for months, and one day it decided to stop working. I haven’t changed the code, nor updated Unity (well, I did install 3.5 beta, but I don’t use it).
I have provided a stripped-down version of my project, with only a separate executable running in the background and Unity trying to connect to it. To use, simply run the executable t/bin/Debug/t.exe and then run the Unity project to connect to the tcplistener. This setup has worked for me for months, but now Unity refuses to connect to the server and I’ve spent the last two days failing to understand why. Actually, Unity will connect to the server, but only if it is run through Visual Studio. As a standalone .exe, it won’t
Here is the project:
805491–29705–$TcpProject.zip (178 KB)
Here is the only code there is:
Project.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;
namespace ThreadingTest
{
class Program
{
static int portNum = 9440;
class Server
{
private TcpListener tcpListener = null;
public Server()
{
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
tcpListener = new TcpListener(localAddr, portNum);
tcpListener.Start();
Console.WriteLine("after tcpListener.Start()");
}
}
static void Main(string[] args)
{
Server s = new Server();
while (true) ;
}
}
}
And the only code being run in Unity:
SpeechTemp.cs
using UnityEngine;
using System.Collections;
using System.Net;
using System.Net.Sockets;
public class SpeechTemp : MonoBehaviour {
TcpClient server;
// Use this for initialization
void Start ()
{
try
{
server = new TcpClient("127.0.0.1", 9440);
print(server);
print("Client connected");
}
catch (SocketException)
{
print("ERROR");
return;
}
}
}
I was suspecting that it had something to do with my firewall, but disabling it has done nothing.
Thank you for your help