2013-07-17 2 views
0

최근에 저는 C#에서 동일한 응용 프로그램을 개발하려고하는 C# Metro 응용 프로그램을 개발했습니다. 그래서 메트로 애플 리케이션 라이브러리 덕분에 website 라이브러리 덕분에 windows.networking.proximity가 여전히 작동하고 windows.security.cryptography도 사용 가능하지만 windows.networking.sockets는 작동하지 않습니다. 내 코드의이 부분의 목표는 와이파이가 스마트 폰에서 전송 된 데이터를 수신하기 위해 단지이다 : 나는이 코드를 빌드 할 때라이브러리를 사용하여 dekstop 응용 프로그램의 Windows.Networking.Sockets (메트로 응용 프로그램) #

` 가 발생합니다 오류가 없습니다

namespace OpenItForMeDesktop{ 
class Server 
{ 
    private StreamSocketListener serverListener; 
    public static String port = "3011"; 
    public static String adressIP = "192.168.173.1"; 
    private HostName hostName; 

    //Initialize the server 
    public Server() 
    { 
     serverListener = new StreamSocketListener(); 
     hostName = new HostName(adressIP); 
     listen(); 
    } 

    //Create the listener which is waiting for connection 
    private async void listen() 
    { 
     serverListener.ConnectionReceived += OnConnection; 
     try 
     { 

      //await serverListener.BindEndpointAsync(hostName, port); 
      await serverListener.BindServiceNameAsync(port); 
      MainWindow.Current.UpdateLog("Listening for Connection(s)"); 
     } 
     catch (Exception exception) 
     { 
      MainWindow.Current.UpdateLog("Exception throw in Listen : " + exception); 
     } 

    } 

    //When a connection appears, this function his called 
    private async void OnConnection(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args) 
    { 

     MainWindow.Current.UpdateLog("A message has been received..."); 
     if (MainWindow.Current.loadingPage) 
     { 
      MainWindow.Current.UpdateLog("wait please"); 
     } 
     else 
     { 

      DataReader reader = new DataReader(args.Socket.InputStream); 
      try 
      { 
       while (true) 
       { 

        reader.InputStreamOptions = InputStreamOptions.Partial; 
        // Read first 4 bytes (length of the subsequent string). 
        uint sizeFieldCount = await reader.LoadAsync(sizeof(uint)); 
        if (sizeFieldCount != sizeof(uint)) 
        { 
         return; 
        } 

        // Read the string. 
        uint stringLength = reader.ReadUInt32(); 
        uint actualStringLength = await reader.LoadAsync(stringLength); 
        if (stringLength != actualStringLength) 
        { 
         return; 
        } 
        String message = reader.ReadString(actualStringLength); 
        MainWindow.Current.receiveMessage(message); 
       } 
      } 
      catch (Exception exception) 
      { 
       // If this is an unknown status it means that the error is fatal and retry will likely fail. 
       if (SocketError.GetStatus(exception.HResult) == SocketErrorStatus.Unknown) 
       { 
        throw; 
       } 

       MainWindow.Current.UpdateLog("Read stream failed with error: " + exception.Message); 
      } 
     } 
    } 




} 

을} 및 smarpthone에서 보낸 패킷을보기 위해 wireshark를 사용할 때 메트로 앱 [SYN]/[SYN, ACK]/[SYN]을 사용할 때 수신 한 첫 번째 패킷 3 개가 아닌 [SYN] ACK]를 송신한다. 누군가 이런 일이 일어나는 이유가 있습니까?

답변

1

나는 대답을 발견했다. 그것은 바보 같았다. 나의 방화벽을 막고있는 방화벽이었다.

0

당신이 Package.appxmanifest에

<Capability Name="privateNetworkClientServer" /> 

를 추가 했습니까?

+0

예 이미 완료되었습니다. – user2429082

관련 문제