Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
SocketSiverlight for Windows Phone            Silverlight     in⼤大   #19     (Microsoft MVP for Windows Phone)
⾃自⼰己• •      –         iPhone / Android     –         Windows Phone     –           •  EbIRC (WM5/6)          •  ZEROProxy...
•                ⽤用    ⽤用•         ⻄西                  ⽉月•                   ⼟土     ⼤大                  ⼤大     –      –   ...
•  Windows Phone “Mango” Socket•       Windows Mobile 6.x   .NET Compact Framework     –  ⾮非•                     ⽻羽⽬目•   ...
•  .NET Fx Silverlight Socket•      –      – • 
.NET Fx Silverlight Socket•  .NET Fx Silverlight for Windows Phone            System.Net.Socket• •  Silverlight Socket  – ...
.NET Framework                                Socketpublic IAsyncResult BeginReceive(byte[ ] buffer, int offset, int size,...
Silverlight for WP                     Socket     public bool ReceiveAsync(SocketAsyncEventArgs e)                      ( ...
•      –                   Socket          •           • •                           ⼊入     –  .NET Framework        ⾚赤
•  .NET Frameworkm_socket = new Socket(AddressFamily.InterNetwork,                      SocketType.Stream, ProtocolType.Tc...
•  Silverlight for Windows PhoneSocketAsyncEventArgs eargs = new SocketAsyncEventArgs();eargs.RemoteEndPoint = remoteEndPo...
•  .NET Frameworkm_stream = new NetworkStream(socket);m_reader = new StreamReader(m_stream, this.Encoding);while (true){  ...
•  Silverlight for Windows Phone  m_receiveBuffer = new byte[2048];	 SocketAsyncEventArgs e = new SocketAsyncEventArgs();e...
•  Silverlight for Windows Phonevoid ReceiveCompleted(object sender, SocketAsyncEventArgs e){      if (e.SocketError == So...
•  .NET Compact Framework•      –      –               ⽕火•      –            •  DnsEndPoint     –      –                  ...
Demo• 
•  Socket     –  Background Agent             ⾏行行        •  Socket             ⽤用     –  IRC        •                     ...
Upcoming SlideShare
Loading in …5
×

Socketプログラム Silverlight for Windows Phoneへの移植のポイント

2,422 views

Published on

Published in: Technology
  • Be the first to comment

Socketプログラム Silverlight for Windows Phoneへの移植のポイント

  1. 1. SocketSiverlight for Windows Phone Silverlight in⼤大 #19 (Microsoft MVP for Windows Phone)
  2. 2. ⾃自⼰己• •  –  iPhone / Android –  Windows Phone –  •  EbIRC (WM5/6) •  ZEROProxy (WM5/6) •  Giraffe (WM5/6) •  SongTweeter (WP7)
  3. 3. •  ⽤用 ⽤用•  ⻄西 ⽉月•  ⼟土 ⼤大 ⼤大 –  –  – 
  4. 4. •  Windows Phone “Mango” Socket•  Windows Mobile 6.x .NET Compact Framework –  ⾮非•  ⽻羽⽬目•  Socket
  5. 5. •  .NET Fx Silverlight Socket•  –  – • 
  6. 6. .NET Fx Silverlight Socket•  .NET Fx Silverlight for Windows Phone System.Net.Socket• •  Silverlight Socket –  NetworkStream •  StreamReader •  ⼿手 –  SslStream SSL ( )
  7. 7. .NET Framework Socketpublic IAsyncResult BeginReceive(byte[ ] buffer, int offset, int size, SocketFlagssocketFlags, out SocketError errorCode, AsyncCallback callback, object state) Begin- / End- IAsyncResult
  8. 8. Silverlight for WP Socket public bool ReceiveAsync(SocketAsyncEventArgs e) ( ) 2 EventArgs ⾮非 ⾮非 ⼊入 true
  9. 9. •  –  Socket •  • •  ⼊入 –  .NET Framework ⾚赤
  10. 10. •  .NET Frameworkm_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);m_connectAsync = m_socket.BeginConnect(remoteEndPoint, new AsyncCallback(OnConnected), m_socket);protected void OnConnected(IAsyncResult ar){ try { // // ( EndConnect SocketException ) Socket socket = (Socket)ar.AsyncState; socket.EndConnect(ar); IAsyncResult
  11. 11. •  Silverlight for Windows PhoneSocketAsyncEventArgs eargs = new SocketAsyncEventArgs();eargs.RemoteEndPoint = remoteEndPoint;eargs.Completed += new EventHandler<SocketAsyncEventArgs>(ConnectCompleted);m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); EventArgsif (!m_socket.ConnectAsync(eargs)){ // ConnectCompleted(m_socket, eargs);} ⾃自
  12. 12. •  .NET Frameworkm_stream = new NetworkStream(socket);m_reader = new StreamReader(m_stream, this.Encoding);while (true){ string line =m_reader.ReadLine(); -- --} NetworkStream StreamReader 1 ⾏行行
  13. 13. •  Silverlight for Windows Phone m_receiveBuffer = new byte[2048]; SocketAsyncEventArgs e = new SocketAsyncEventArgs();e.SetBuffer(m_receiveBuffer, 0, m_receiveBuffer.Length);e.Completed += new EventHandler<SocketAsyncEventArgs>(ReceiveCompleted); m_socket.ReceiveAsync(e); ⾃自
  14. 14. •  Silverlight for Windows Phonevoid ReceiveCompleted(object sender, SocketAsyncEventArgs e){ if (e.SocketError == SocketError.Success) { if (e.BytesTransferred > 0) { ⾃自 // snip ⾃自 } if (!m_sendLoopStop) Receive(); ⾃自 BeginReceive } else { ProcessSocketError(e.SocketError); }}
  15. 15. •  .NET Compact Framework•  –  –  ⽕火•  –  •  DnsEndPoint –  –  (Control.Invoke/ Dispatcher.Invoke)
  16. 16. Demo• 
  17. 17. •  Socket –  Background Agent ⾏行行 •  Socket ⽤用 –  IRC •  IRC •  IRC Toast •  iOS4 Long-time Task ⾔言•  UX –  ⾃自 –  ⼀一 (pirc )

×