从Windows Phone应用程序8传输TCP套接字. [英] TCP sockets transfer from windows phone app 8.

查看:79
本文介绍了从Windows Phone应用程序8传输TCP套接字.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个示例,我试图使用TCP将客户端(Windows Phone 8)应用程序中的数据传输到Windows窗体应用程序(充当服务器)中.

i am doing a sample in which I am trying to transfer data from client(windows phone 8) app to  windows form app(which acts as a server) using TCP.

在Windows窗体应用中,我正在创建一个这样的侦听器

In windows form app I am creating a listener like this

TcpListener tcpListener = null;

            IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList [0];
           试试
            {
                //将侦听器设置为本地IP地址
                //并指定端口.
                tcpListener = new TcpListener(ipAddress,13);
                tcpListener.Start();
               输出=正在等待连接...";
            }
            catch(异常e)
            {
               输出=错误:" + e.ToString();
                MessageBox.Show(输出);
            }

           而(true)
            {

                Thread.Sleep(10);
                  TcpClient tcpClient = tcpListener.AcceptTcpClient();

                byte []个字节=新的字节[256];

                NetworkStream流= tcpClient.GetStream();
                stream.Read(bytes,0,bytes.Length);

TcpListener tcpListener = null;

            IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
            try
            {
                // Set the listener on the local IP address
                // and specifing the port.
                tcpListener = new TcpListener(ipAddress, 13);
                tcpListener.Start();
                output = "Waiting for a connection...";
            }
            catch (Exception e)
            {
                output = "Error: " + e.ToString();
                MessageBox.Show(output);
            }

            while (true)
            {

                Thread.Sleep(10);
                 TcpClient tcpClient = tcpListener.AcceptTcpClient();

                byte[] bytes = new byte[256];

                NetworkStream stream = tcpClient.GetStream();
                stream.Read(bytes, 0, bytes.Length);

              }

              }

 在Windows Phone 8应用中,我正在使用托管套接字将诸如此类的内容连接到侦听器

 In windows phone 8 app i am using managed sockets to connect to the listener some thing like this

 但是我收到了拒绝连接的套接字错误.是我的方法是正确的,如何通过Windows Phone连接TCP侦听器.在这里,我无法更改Windows Form应用程序的代码,因为它是我的实时服务器代码. 更改服务器的代码....

  But i got an socket error of connection refused. Is my approach is correct, how to connect a tcp listener through windows phone.. Here i cannot change the code of windows form app as it was my server code in the real time.. Or is it compulsary to change the code of my server.... 

推荐答案

您可能想编写一个与服务器通信的测试Windows应用程序,以验证服务器端能否正常运行.然后,使用手机将使用的相同WiFi,通过WiFi使Windows应用程序正常工作.然后测试Windows Phone应用.

You might want to write a test Windows app that talks to your server, to verify that the server side works fine. Then get the windows app to work via a WiFi, using the same WiFi that the phone will use. Then test the windows phone app.

如果尝试与作为LocalHost的测试服务器(IIS)进行通信,我认为您的电话需要通过物理IP地址来引用服务器,因为电话是网络上单独的离散实体.

If trying to communicate with a test server (IIS) that is LocalHost, I believe your phone needs to reference the server by physical IP address because the phone is a separate discrete entity on the network.

希望这会有所帮助,
标记

Hope this helps,
Mark


这篇关于从Windows Phone应用程序8传输TCP套接字.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆