Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hello Socket Programming TCP and UDP

Similar presentations


Presentation on theme: "Hello Socket Programming TCP and UDP"— Presentation transcript:

1 Hello Socket Programming TCP and UDP
Android Introduction Hello Socket Programming TCP and UDP

2 Goal Convert the Java Socket Programming Project to Android
Text input from the user – sent to the same server(s) as before Answer from the server(s) Sends the input from the user to the UPD Server Sends the input from the user to the TCP Server

3 Layout Create a simple layout that will include the required elements:
EditText TextView Buttons Register one “OnClickedListener()” for each of the buttons Test functionality (make a toast for each listener)

4 Socket Programming Define most variables as members of the main Activity Class Rename: DatagramSocket clientSocket -> DatagramSocket udpClientSocket Socket clientSocket -> Socket tcpSocket; Adapt the code from pure Java to Android (especially the input and output strings) by filling in the two OnClickListeners

5 Handling Exceptions Many network operations throw exceptions (as they can fail). In the original code they were just thrown out of main – in Android we have to handle them! Try{ Operations that may fail and throw an exception; }catch (Exception e) { Log.e(TAG,"Caught UDP Exception: “ + e.getMessage()); Toast.makeText(HelloNets.this, "UDP Error"+ e.getMessage()), Toast.LENGTH_LONG).show(); }

6 Running it First give the application INTERNET permissions (like in the WebView) Implement the UDP and TCP functionality separately Run and debug.


Download ppt "Hello Socket Programming TCP and UDP"

Similar presentations


Ads by Google