SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
Socket
Siverlight for Windows Phone

            Silverlight     in⼤大   #19

     (Microsoft MVP for Windows Phone)
⾃自⼰己
• 
• 
     –         iPhone / Android
     –         Windows Phone
     – 
          •  EbIRC (WM5/6)
          •  ZEROProxy (WM5/6)
          •  Giraffe (WM5/6)
          •  SongTweeter (WP7)
• 
               ⽤用    ⽤用
•         ⻄西                  ⽉月


•                   ⼟土
     ⼤大                  ⼤大

     – 
     – 
     – 
•  Windows Phone “Mango” Socket
•       Windows Mobile 6.x
   .NET Compact Framework

     –  ⾮非


•                     ⽻羽⽬目
•            Socket
•  .NET Fx Silverlight Socket
• 
     – 
     – 
• 
.NET Fx Silverlight Socket
•  .NET Fx Silverlight for Windows Phone
            System.Net.Socket
• 

•  Silverlight Socket
  –  NetworkStream
     •    StreamReader
     •                   ⼿手
  –  SslStream
     SSL       (              )
.NET Framework                                Socket




public IAsyncResult BeginReceive(byte[ ] buffer, int offset, int size, SocketFlags
socketFlags, out SocketError errorCode, AsyncCallback callback, object state)




                                   Begin- / End-    IAsyncResult
Silverlight for WP                     Socket




     public bool ReceiveAsync(SocketAsyncEventArgs e)




                      (        )   2    EventArgs     ⾮非
                          ⾮非           ⼊入           true
• 
     –                   Socket

          • 

          • 


•                           ⼊入
     –  .NET Framework
        ⾚赤
•  .NET Framework
m_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
•  Silverlight for Windows Phone
SocketAsyncEventArgs eargs = new SocketAsyncEventArgs();
eargs.RemoteEndPoint = remoteEndPoint;
eargs.Completed +=
             new EventHandler<SocketAsyncEventArgs>(ConnectCompleted);

m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
                              ProtocolType.Tcp);       EventArgs
if (!m_socket.ConnectAsync(eargs))
{
       //                            	
 
	
 	
 	
 	
 ConnectCompleted(m_socket, eargs);
}


                                             ⾃自
•  .NET Framework
m_stream = new NetworkStream(socket);
m_reader = new StreamReader(m_stream, this.Encoding);
while (true)
{
  string line =m_reader.ReadLine();
  --           --
}
                               NetworkStream




 StreamReader            1   ⾏行行
•  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);


                                    ⾃自
•  Silverlight for Windows Phone
void ReceiveCompleted(object sender, SocketAsyncEventArgs e)
{
      if (e.SocketError == SocketError.Success)
      {
 	
 	
 	
 	
 	
 	
 	
 if (e.BytesTransferred > 0)
             {                                            ⾃自
                   // snip                           ⾃自
             }
             if (!m_sendLoopStop)
                   Receive();
                                              ⾃自  BeginReceive
      }
      else
      {
             ProcessSocketError(e.SocketError);
      }
}
•  .NET Compact Framework

• 
     – 
     –               ⽕火
• 
     – 
           •  DnsEndPoint

     – 
     –                     (Control.Invoke/
          Dispatcher.Invoke)
Demo
• 
•  Socket
     –  Background Agent             ⾏行行

        •  Socket             ⽤用
     –  IRC
        •                                  IRC
        •  IRC                                   Toast
        •  iOS4     Long-time Task     ⾔言

•                                    UX
     –                         ⾃自
     –  ⼀一                 (pirc            )

Mais conteúdo relacionado

Mais procurados

HTTPプロクシライブラリproxy2の設計と実装
HTTPプロクシライブラリproxy2の設計と実装HTTPプロクシライブラリproxy2の設計と実装
HTTPプロクシライブラリproxy2の設計と実装
inaz2
 
Csw2016 d antoine_automatic_exploitgeneration
Csw2016 d antoine_automatic_exploitgenerationCsw2016 d antoine_automatic_exploitgeneration
Csw2016 d antoine_automatic_exploitgeneration
CanSecWest
 
Possibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented ProgrammingPossibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented Programming
kozossakai
 
BlueHat v18 || The matrix has you - protecting linux using deception
BlueHat v18 || The matrix has you - protecting linux using deceptionBlueHat v18 || The matrix has you - protecting linux using deception
BlueHat v18 || The matrix has you - protecting linux using deception
BlueHat Security Conference
 

Mais procurados (20)

Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#Defcon 27 - Writing custom backdoor payloads with C#
Defcon 27 - Writing custom backdoor payloads with C#
 
Nsa and vpn
Nsa and vpnNsa and vpn
Nsa and vpn
 
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru OtsukaTake a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
 
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
BSides LV 2016 - Beyond the tip of the iceberg - fuzzing binary protocols for...
 
Scapy TLS: A scriptable TLS 1.3 stack
Scapy TLS: A scriptable TLS 1.3 stackScapy TLS: A scriptable TLS 1.3 stack
Scapy TLS: A scriptable TLS 1.3 stack
 
HTTPプロクシライブラリproxy2の設計と実装
HTTPプロクシライブラリproxy2の設計と実装HTTPプロクシライブラリproxy2の設計と実装
HTTPプロクシライブラリproxy2の設計と実装
 
Penetration Testing Resource Guide
Penetration Testing Resource Guide Penetration Testing Resource Guide
Penetration Testing Resource Guide
 
Pentesting custom TLS stacks
Pentesting custom TLS stacksPentesting custom TLS stacks
Pentesting custom TLS stacks
 
A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...
A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...
A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...
 
Docker Security
Docker SecurityDocker Security
Docker Security
 
Csw2016 d antoine_automatic_exploitgeneration
Csw2016 d antoine_automatic_exploitgenerationCsw2016 d antoine_automatic_exploitgeneration
Csw2016 d antoine_automatic_exploitgeneration
 
SELinux Kernel Internals and Architecture - FOSS.IN/2005
SELinux Kernel Internals and Architecture - FOSS.IN/2005SELinux Kernel Internals and Architecture - FOSS.IN/2005
SELinux Kernel Internals and Architecture - FOSS.IN/2005
 
Possibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented ProgrammingPossibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented Programming
 
How Safe is your Link ?
How Safe is your Link ?How Safe is your Link ?
How Safe is your Link ?
 
Vm ware fuzzing - defcon russia 20
Vm ware fuzzing  - defcon russia 20Vm ware fuzzing  - defcon russia 20
Vm ware fuzzing - defcon russia 20
 
Ubuntu: Setup development environment for ruby on rails
Ubuntu:  Setup development environment for ruby on railsUbuntu:  Setup development environment for ruby on rails
Ubuntu: Setup development environment for ruby on rails
 
BlueHat v18 || The matrix has you - protecting linux using deception
BlueHat v18 || The matrix has you - protecting linux using deceptionBlueHat v18 || The matrix has you - protecting linux using deception
BlueHat v18 || The matrix has you - protecting linux using deception
 
Ch 5: Port Scanning
Ch 5: Port ScanningCh 5: Port Scanning
Ch 5: Port Scanning
 
Loophole: Timing Attacks on Shared Event Loops in Chrome
Loophole: Timing Attacks on Shared Event Loops in ChromeLoophole: Timing Attacks on Shared Event Loops in Chrome
Loophole: Timing Attacks on Shared Event Loops in Chrome
 
Assume Compromise
Assume CompromiseAssume Compromise
Assume Compromise
 

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

Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
Praveen Gollakota
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
Serge Stinckwich
 
04 android
04 android04 android
04 android
guru472
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
Rick Copeland
 

Semelhante a Socketプログラム Silverlight for Windows Phoneへの移植のポイント (20)

Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections
 
Tornado Web Server Internals
Tornado Web Server InternalsTornado Web Server Internals
Tornado Web Server Internals
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
分散式系統
分散式系統分散式系統
分散式系統
 
Cp7 rpc
Cp7 rpcCp7 rpc
Cp7 rpc
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Socket & Server Socket
Socket & Server SocketSocket & Server Socket
Socket & Server Socket
 
Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
 
04 android
04 android04 android
04 android
 
An Introduction to Twisted
An Introduction to TwistedAn Introduction to Twisted
An Introduction to Twisted
 
Jugando con websockets en nodeJS
Jugando con websockets en nodeJSJugando con websockets en nodeJS
Jugando con websockets en nodeJS
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
Networking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in programNetworking.ppt(client/server, socket) uses in program
Networking.ppt(client/server, socket) uses in program
 
Real-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.ioReal-Time Python Web: Gevent and Socket.io
Real-Time Python Web: Gevent and Socket.io
 
Comunicando nuestras apps con el mundo exterior
Comunicando nuestras apps con el mundo exteriorComunicando nuestras apps con el mundo exterior
Comunicando nuestras apps con el mundo exterior
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 

Mais de Shin Ise

Cross platform development with Xamarin 2.0 + MvvmCross
Cross platform development with Xamarin 2.0 + MvvmCrossCross platform development with Xamarin 2.0 + MvvmCross
Cross platform development with Xamarin 2.0 + MvvmCross
Shin Ise
 
いまどきのiOSプログラミング with Xcode5
いまどきのiOSプログラミング with Xcode5いまどきのiOSプログラミング with Xcode5
いまどきのiOSプログラミング with Xcode5
Shin Ise
 
すまべんLite@関西#4
すまべんLite@関西#4すまべんLite@関西#4
すまべんLite@関西#4
Shin Ise
 
すまべんLite@関西#3
すまべんLite@関西#3すまべんLite@関西#3
すまべんLite@関西#3
Shin Ise
 
すまべんLite@関西#2
すまべんLite@関西#2すまべんLite@関西#2
すまべんLite@関西#2
Shin Ise
 
すごいHaskell読書会#10
すごいHaskell読書会#10すごいHaskell読書会#10
すごいHaskell読書会#10
Shin Ise
 
音声APIを使ってみる
音声APIを使ってみる音声APIを使ってみる
音声APIを使ってみる
Shin Ise
 
すまべんLite@関西#1
すまべんLite@関西#1すまべんLite@関西#1
すまべんLite@関西#1
Shin Ise
 
Xamarin2.0であそぼう
Xamarin2.0であそぼうXamarin2.0であそぼう
Xamarin2.0であそぼう
Shin Ise
 
CoreBluetoothでつくるBluetooth Low Energyデバイス
CoreBluetoothでつくるBluetooth Low EnergyデバイスCoreBluetoothでつくるBluetooth Low Energyデバイス
CoreBluetoothでつくるBluetooth Low Energyデバイス
Shin Ise
 
すごいHaskell読書会 in 大阪 #4 「第6章 モジュール」
すごいHaskell読書会 in 大阪 #4 「第6章 モジュール」すごいHaskell読書会 in 大阪 #4 「第6章 モジュール」
すごいHaskell読書会 in 大阪 #4 「第6章 モジュール」
Shin Ise
 
GridViewのつかいかた
GridViewのつかいかたGridViewのつかいかた
GridViewのつかいかた
Shin Ise
 
iOSのVoiceOver対応開発 Rev2
iOSのVoiceOver対応開発 Rev2iOSのVoiceOver対応開発 Rev2
iOSのVoiceOver対応開発 Rev2
Shin Ise
 
MediaLibrary で あそぼう
MediaLibrary で あそぼうMediaLibrary で あそぼう
MediaLibrary で あそぼう
Shin Ise
 
実践 Reactive Extensions
実践 Reactive Extensions実践 Reactive Extensions
実践 Reactive Extensions
Shin Ise
 
本当は怖いSilverlight for Windows Phone Toolkit
本当は怖いSilverlight for Windows Phone Toolkit本当は怖いSilverlight for Windows Phone Toolkit
本当は怖いSilverlight for Windows Phone Toolkit
Shin Ise
 
Macで使うWindows Phone 7
Macで使うWindows Phone 7Macで使うWindows Phone 7
Macで使うWindows Phone 7
Shin Ise
 
Galaxy tab で持ち歩くモバイルサーバー
Galaxy tab で持ち歩くモバイルサーバーGalaxy tab で持ち歩くモバイルサーバー
Galaxy tab で持ち歩くモバイルサーバー
Shin Ise
 
ハブインテグレーションでWindows Phone 7の世界に溶け込むアプリを作る
ハブインテグレーションでWindows Phone 7の世界に溶け込むアプリを作るハブインテグレーションでWindows Phone 7の世界に溶け込むアプリを作る
ハブインテグレーションでWindows Phone 7の世界に溶け込むアプリを作る
Shin Ise
 

Mais de Shin Ise (20)

Cross platform development with Xamarin 2.0 + MvvmCross
Cross platform development with Xamarin 2.0 + MvvmCrossCross platform development with Xamarin 2.0 + MvvmCross
Cross platform development with Xamarin 2.0 + MvvmCross
 
いまどきのiOSプログラミング with Xcode5
いまどきのiOSプログラミング with Xcode5いまどきのiOSプログラミング with Xcode5
いまどきのiOSプログラミング with Xcode5
 
すまべんLite@関西#4
すまべんLite@関西#4すまべんLite@関西#4
すまべんLite@関西#4
 
すまべんLite@関西#3
すまべんLite@関西#3すまべんLite@関西#3
すまべんLite@関西#3
 
すまべんLite@関西#2
すまべんLite@関西#2すまべんLite@関西#2
すまべんLite@関西#2
 
すごいHaskell読書会#10
すごいHaskell読書会#10すごいHaskell読書会#10
すごいHaskell読書会#10
 
音声APIを使ってみる
音声APIを使ってみる音声APIを使ってみる
音声APIを使ってみる
 
すまべんLite@関西#1
すまべんLite@関西#1すまべんLite@関西#1
すまべんLite@関西#1
 
Xamarin2.0であそぼう
Xamarin2.0であそぼうXamarin2.0であそぼう
Xamarin2.0であそぼう
 
CoreBluetoothでつくるBluetooth Low Energyデバイス
CoreBluetoothでつくるBluetooth Low EnergyデバイスCoreBluetoothでつくるBluetooth Low Energyデバイス
CoreBluetoothでつくるBluetooth Low Energyデバイス
 
すごいHaskell読書会 in 大阪 #4 「第6章 モジュール」
すごいHaskell読書会 in 大阪 #4 「第6章 モジュール」すごいHaskell読書会 in 大阪 #4 「第6章 モジュール」
すごいHaskell読書会 in 大阪 #4 「第6章 モジュール」
 
GridViewのつかいかた
GridViewのつかいかたGridViewのつかいかた
GridViewのつかいかた
 
iOSのVoiceOver対応開発 Rev2
iOSのVoiceOver対応開発 Rev2iOSのVoiceOver対応開発 Rev2
iOSのVoiceOver対応開発 Rev2
 
MediaLibrary で あそぼう
MediaLibrary で あそぼうMediaLibrary で あそぼう
MediaLibrary で あそぼう
 
実践 Reactive Extensions
実践 Reactive Extensions実践 Reactive Extensions
実践 Reactive Extensions
 
本当は怖いSilverlight for Windows Phone Toolkit
本当は怖いSilverlight for Windows Phone Toolkit本当は怖いSilverlight for Windows Phone Toolkit
本当は怖いSilverlight for Windows Phone Toolkit
 
Macで使うWindows Phone 7
Macで使うWindows Phone 7Macで使うWindows Phone 7
Macで使うWindows Phone 7
 
iOSのVoiceOver対応開発
iOSのVoiceOver対応開発iOSのVoiceOver対応開発
iOSのVoiceOver対応開発
 
Galaxy tab で持ち歩くモバイルサーバー
Galaxy tab で持ち歩くモバイルサーバーGalaxy tab で持ち歩くモバイルサーバー
Galaxy tab で持ち歩くモバイルサーバー
 
ハブインテグレーションでWindows Phone 7の世界に溶け込むアプリを作る
ハブインテグレーションでWindows Phone 7の世界に溶け込むアプリを作るハブインテグレーションでWindows Phone 7の世界に溶け込むアプリを作る
ハブインテグレーションでWindows Phone 7の世界に溶け込むアプリを作る
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 

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

  • 1. Socket Siverlight for Windows Phone Silverlight in⼤大 #19 (Microsoft MVP for Windows Phone)
  • 2. ⾃自⼰己 •  •  –  iPhone / Android –  Windows Phone –  •  EbIRC (WM5/6) •  ZEROProxy (WM5/6) •  Giraffe (WM5/6) •  SongTweeter (WP7)
  • 3. •  ⽤用 ⽤用 •  ⻄西 ⽉月 •  ⼟土 ⼤大 ⼤大 –  –  – 
  • 4. •  Windows Phone “Mango” Socket •  Windows Mobile 6.x .NET Compact Framework –  ⾮非 •  ⽻羽⽬目 •  Socket
  • 5. •  .NET Fx Silverlight Socket •  –  –  • 
  • 6. .NET Fx Silverlight Socket •  .NET Fx Silverlight for Windows Phone System.Net.Socket •  •  Silverlight Socket –  NetworkStream •  StreamReader •  ⼿手 –  SslStream SSL ( )
  • 7. .NET Framework Socket public IAsyncResult BeginReceive(byte[ ] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, object state) Begin- / End- IAsyncResult
  • 8. Silverlight for WP Socket public bool ReceiveAsync(SocketAsyncEventArgs e) ( ) 2 EventArgs ⾮非 ⾮非 ⼊入 true
  • 9. •  –  Socket •  •  •  ⼊入 –  .NET Framework ⾚赤
  • 10. •  .NET Framework m_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. •  Silverlight for Windows Phone SocketAsyncEventArgs eargs = new SocketAsyncEventArgs(); eargs.RemoteEndPoint = remoteEndPoint; eargs.Completed += new EventHandler<SocketAsyncEventArgs>(ConnectCompleted); m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); EventArgs if (!m_socket.ConnectAsync(eargs)) { // ConnectCompleted(m_socket, eargs); } ⾃自
  • 12. •  .NET Framework m_stream = new NetworkStream(socket); m_reader = new StreamReader(m_stream, this.Encoding); while (true) { string line =m_reader.ReadLine(); -- -- } NetworkStream StreamReader 1 ⾏行行
  • 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. •  Silverlight for Windows Phone void 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. •  .NET Compact Framework •  –  –  ⽕火 •  –  •  DnsEndPoint –  –  (Control.Invoke/ Dispatcher.Invoke)
  • 17. •  Socket –  Background Agent ⾏行行 •  Socket ⽤用 –  IRC •  IRC •  IRC Toast •  iOS4 Long-time Task ⾔言 •  UX –  ⾃自 –  ⼀一 (pirc )