Use library Windows.Networking.Sockets ( metro app ) in a dekstop app c# -


recently i've developped c# metro app works , want developp same app in c#. i've done few things enable use of metro app library website library windows.networking.proximity still working, windows.security.cryptography apparently windows.networking.sockets doesn't work. goal in part of code, receive data sent smartphone wifi:

namespace openitformedesktop{ class server {     private streamsocketlistener serverlistener;     public static string port = "3011";     public static string adressip = "192.168.173.1";     private hostname hostname;      //initialize server     public server()     {         serverlistener = new streamsocketlistener();         hostname = new hostname(adressip);         listen();     }      //create listener waiting connection     private async void listen()     {         serverlistener.connectionreceived += onconnection;         try         {              //await serverlistener.bindendpointasync(hostname, port);             await serverlistener.bindservicenameasync(port);             mainwindow.current.updatelog("listening connection(s)");         }         catch (exception exception)         {             mainwindow.current.updatelog("exception throw in listen : " + exception);         }      }      //when connection appears, function 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 subsequent string).                     uint sizefieldcount = await reader.loadasync(sizeof(uint));                     if (sizefieldcount != sizeof(uint))                     {                         return;                     }                      // read 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 unknown status means error fatal , retry fail.                 if (socketerror.getstatus(exception.hresult) == socketerrorstatus.unknown)                 {                     throw;                 }                  mainwindow.current.updatelog("read stream failed error: " + exception.message);             }         }     }     } 

}

` when build code there no error thrown, , when use wireshark see packet sent smarpthone, received packet flag [syn] , not 3 first packets received when i'm using metro app [syn]/[syn,ack]/[ack] handshake. idea why happen?

i found answer, quite stupid, firewall of windows blocking app.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -