C# 统一套接字项目don';安装到iPhone时无法工作

C# 统一套接字项目don';安装到iPhone时无法工作,c#,ios,iphone,sockets,unity3d,C#,Ios,Iphone,Sockets,Unity3d,我与socket通信相关的Unity项目在Mac上运行良好。我在自己的计算机终端上运行C#server,然后运行unity项目。unity项目可以连接到我的服务器并接收服务器发送的消息。一切正常。然而,当我在iPhone上构建并运行此unity项目时,会出现一些问题: 2016-12-26 12:43:43.915127 ProductName[8497:5717779] [DYMTLInitPlatform] platform initialization successful 2016-1

我与socket通信相关的Unity项目在Mac上运行良好。我在自己的计算机终端上运行C#server,然后运行unity项目。unity项目可以连接到我的服务器并接收服务器发送的消息。一切正常。然而,当我在iPhone上构建并运行此unity项目时,会出现一些问题:

2016-12-26 12:43:43.915127 ProductName[8497:5717779] [DYMTLInitPlatform] platform initialization successful

2016-12-26 12:43:44.095512 ProductName[8497:5717642] -> registered mono modules 0xb94140
2016-12-26 12:43:44.646127 ProductName[8497:5717642] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
-> applicationDidFinishLaunching()
2016-12-26 12:43:44.810782 ProductName[8497:5717642] Metal GPU Frame Capture Enabled
2016-12-26 12:43:44.811680 ProductName[8497:5717642] Metal API Validation Enabled
-> applicationDidBecomeActive()
Renderer: PowerVR SGX 543
Vendor:   Imagination Technologies
Version:  OpenGL ES 2.0 IMGSGX543-128
GLES:     2
GL_OES_depth_texture GL_OES_depth24 GL_OES_element_index_uint GL_OES_fbo_render_mipmap GL_OES_mapbuffer GL_OES_packed_depth_stencil GL_OES_rgb8_rgba8 GL_OES_standard_derivatives GL_OES_texture_float GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_vertex_array_object GL_EXT_blend_minmax GL_EXT_color_buffer_half_float GL_EXT_debug_label GL_EXT_debug_marker GL_EXT_discard_framebuffer GL_EXT_draw_instanced GL_EXT_instanced_arrays GL_EXT_map_buffer_range GL_EXT_occlusion_query_boolean GL_EXT_pvrtc_sRGB GL_EXT_read_format_bgra GL_EXT_separate_shader_objects GL_EXT_shader_framebuffer_fetch GL_EXT_shader_texture_lod GL_EXT_shadow_samplers GL_EXT_sRGB GL_EXT_texture_filter_anisotropic GL_EXT_texture_rg GL_EXT_texture_storage GL_APPLE_clip_distance GL_APPLE_color_buffer_packed_float GL_APPLE_copy_texture_levels GL_APPLE_framebuffer_multisample GL_APPLE_rgb_422 GL_APPLE_sync GL_APPLE_texture_format_BGRA8888 GL_APPLE_texture_max_level GL_APPLE_texture_packed_float GL_IMG_read_format GL_IMG_texture_comp

ression_pvrtc 
OPENGL LOG: Creating OpenGL ES 2.0 graphics device ; Context level  <OpenGL ES 2.0> ; Context handle 392780752
Initialize engine version: 5.4.2f2 (b7e030c65c9b)
UnloadTime: 5.501916 ms
SocketException: Connection timed out
  at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in <filename unknown>:0 
  at System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] in <filename unknown>:0 

(Filename: currently not available on il2cpp Line: -1)

Setting up 1 worker threads for Enlighten.
  Thread -> id: 40595000 -> priority: 1 
2016-12-26 12:45:01.391673 ProductName[8497:5717642] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2016-12-26 12:45:01.393101 ProductName[8497:5717642] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
下面是我的unity项目的代码:

using UnityEngine;
using System.Collections;
using System;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine.UI;


public class Client : MonoBehaviour {

    System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
    private Thread oThread;

    //  for UI update
    public GameObject updatetext;
    String tempMesg = "Waiting...";

    // Use this for initialization
    void Start () {
        updatetext.GetComponent<Text>().text = "Waiting...";
        clientSocket.Connect("10.132.198.29", 8888);
        oThread = new Thread (new ThreadStart (getInformation));
        oThread.Start ();
        Debug.Log ("Running the client");
    }

    void getInformation(){
        while (true) {
            try {
                NetworkStream networkStream = clientSocket.GetStream ();
                byte[] bytesFrom = new byte[10025];
                networkStream.Read (bytesFrom, 0, (int)bytesFrom.Length);
                string dataFromClient = System.Text.Encoding.ASCII.GetString (bytesFrom);
                dataFromClient = dataFromClient.Substring (0, dataFromClient.IndexOf ("$"));
                Debug.Log (" >> Data from Server - " + dataFromClient);

                tempMesg = dataFromClient;

                string serverResponse = "Last Message from Server" + dataFromClient;

                Byte[] sendBytes = Encoding.ASCII.GetBytes (serverResponse);
                networkStream.Write (sendBytes, 0, sendBytes.Length);
                networkStream.Flush ();
                Debug.Log (" >> " + serverResponse);

            } catch (Exception ex) {
                Debug.Log ("Exception error:" + ex.ToString ());
                oThread.Abort ();
                oThread.Join ();
            }
        }
    }
}
使用UnityEngine;
使用系统集合;
使用制度;
使用System.Net.Sockets;
使用系统文本;
使用系统线程;
使用UnityEngine.UI;
公共类客户端:MonoBehavior{
System.Net.Sockets.TcpClient clientSocket=新系统.Net.Sockets.TcpClient();
私有线程读取;
//用于用户界面更新
公共游戏对象更新文本;
字符串tempMesg=“等待…”;
//用于初始化
无效开始(){
updatetext.GetComponent().text=“等待…”;
clientSocket.Connect(“10.132.198.29”,8888);
oThread=新线程(newthreadstart(getInformation));
oThread.Start();
Log(“运行客户端”);
}
void getInformation(){
while(true){
试一试{
NetworkStream NetworkStream=clientSocket.GetStream();
byte[]bytesFrom=新字节[10025];
networkStream.Read(bytesFrom,0,(int)bytesFrom.Length);
string dataFromClient=System.Text.Encoding.ASCII.GetString(bytesFrom);
dataFromClient=dataFromClient.Substring(0,dataFromClient.IndexOf(“$”);
Log(“>>来自服务器的数据-”+来自客户端的数据);
tempMesg=来自客户端的数据;
string serverResponse=“来自服务器的最后一条消息”+dataFromClient;
Byte[]sendBytes=Encoding.ASCII.GetBytes(serverResponse);
networkStream.Write(sendBytes,0,sendBytes.Length);
Flush();
Debug.Log(“>>”+serverResponse);
}捕获(例外情况除外){
Log(“异常错误:+ex.ToString());
oThread.Abort();
Join();
}
}
}
}

我想知道我是否需要设置一些东西来启用Xcode中的套接字插件?

@程序员我正在尝试连接到一个本地ip地址,我使用ipconfig从我的Mac终端检查它。对不起,我没有Android设备。。。所以我不知道它是否能在android上运行…@程序员我的iPhone是5c,IOS版本是10.2。非常感谢。你试过这个吗?clientSocket.Connect(IPAddress.Parse(IP),端口);我想您需要解析“10.132.198.29”以进行连接。@程序员我正在尝试连接到本地ip地址,我使用ipconfig从Mac终端检查该地址。对不起,我没有Android设备。。。所以我不知道它是否能在android上运行…@程序员我的iPhone是5c,IOS版本是10.2。非常感谢。你试过这个吗?clientSocket.Connect(IPAddress.Parse(IP),端口);我认为您需要解析“10.132.198.29”以获得连接。
using UnityEngine;
using System.Collections;
using System;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using UnityEngine.UI;


public class Client : MonoBehaviour {

    System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
    private Thread oThread;

    //  for UI update
    public GameObject updatetext;
    String tempMesg = "Waiting...";

    // Use this for initialization
    void Start () {
        updatetext.GetComponent<Text>().text = "Waiting...";
        clientSocket.Connect("10.132.198.29", 8888);
        oThread = new Thread (new ThreadStart (getInformation));
        oThread.Start ();
        Debug.Log ("Running the client");
    }

    void getInformation(){
        while (true) {
            try {
                NetworkStream networkStream = clientSocket.GetStream ();
                byte[] bytesFrom = new byte[10025];
                networkStream.Read (bytesFrom, 0, (int)bytesFrom.Length);
                string dataFromClient = System.Text.Encoding.ASCII.GetString (bytesFrom);
                dataFromClient = dataFromClient.Substring (0, dataFromClient.IndexOf ("$"));
                Debug.Log (" >> Data from Server - " + dataFromClient);

                tempMesg = dataFromClient;

                string serverResponse = "Last Message from Server" + dataFromClient;

                Byte[] sendBytes = Encoding.ASCII.GetBytes (serverResponse);
                networkStream.Write (sendBytes, 0, sendBytes.Length);
                networkStream.Flush ();
                Debug.Log (" >> " + serverResponse);

            } catch (Exception ex) {
                Debug.Log ("Exception error:" + ex.ToString ());
                oThread.Abort ();
                oThread.Join ();
            }
        }
    }
}