【问题标题】:TCP sending with Unity使用 Unity 发送 TCP
【发布时间】:2015-03-10 18:08:56
【问题描述】:

我对 Unity 还很陌生,但我创建了一个应用程序,单击按钮即可将简单的 TCP 消息发送到一个非常简单的 TCP 服务器控制台应用程序。该代码在我的 PC 上运行时运行良好,但是当我为 Android 构建它并通过手机对其进行测试时,消息无法到达服务器。我做错了吗?简单的 TCP 交互是否与 android 不同?这是我的 Unity 代码:

public Texture btnTexture;
public GUIStyle style;
TcpClient mySocket = new TcpClient();
public NetworkStream theStream;
public String Host = "my_ip_address";
public Int32 Port = 8888;
public bool sent = false;
StreamWriter theWriter;
StreamReader theReader;

void OnGUI()
{
    if (GUI.Button (new Rect ((Screen.width / 2) - Screen.width/4, (Screen.height / 2) - Screen.height/4, 
                              Screen.width/2, Screen.width/2), btnTexture)) 
    {
        if(!sent)
        {
            mySocket = new TcpClient(Host, Port);
            theStream = mySocket.GetStream();
            theWriter = new StreamWriter(theStream);
            theReader = new StreamReader(theStream);
            sent = true;
        }
        theWriter.Write("TCP Message" + " $");
        theWriter.Flush();
        //Application.LoadLevel ("Page1");
    }

}

【问题讨论】:

    标签: android networking tcp unity3d tcpclient


    【解决方案1】:

    从您发布的日期来看,回答可能为时已晚。但是,我遇到了一些熟悉的问题,但使用的是 iOS。我希望这对以后会搜索此内容的人有所帮助。

    我建议深入研究您用于连接 TCP 连接的库。对于我的问题,原因是来自 TCP libs 正在使用的解析库。解析库在某种程度上是 iOS 没有的东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-15
      • 2017-09-14
      • 2016-04-27
      • 2012-03-14
      • 1970-01-01
      • 2012-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多