Home > Backend Development > PHP Tutorial > Socket usage related

Socket usage related

WBOY
Release: 2016-07-25 09:08:11
Original
841 people have browsed it
Learned in a small practice project                                                                
                                                                                                                                                                                                                                                                                                       
  1. package com.sdut.edu.tools;
  2. import java.io.BufferedWriter;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStreamWriter;
  6. import java. io.PrintWriter;
  7. import java.net.InetSocketAddress;
  8. import java.net.Socket;
  9. import java.net.SocketAddress;
  10. import java.net.SocketException;
  11. import java.util.Scanner;
  12. import android.app .ActivityManager;
  13. import android.app.AlertDialog;
  14. import android.content.Context;
  15. import android.content.DialogInterface;
  16. import android.util.Log;
  17. public class ConnectServer {
  18. connectServer(String str) throws SocketException,IOException
  19.                                                                                                                                                                                                          // TODO Auto-generated method
  20.                 String result = null;
  21. //               try{
  22. int c = 0;​ ​ ​ socket.connect(new InetSocketAddress( "192.168.0.189",4444),4000); Address()==null)
  23. //                                                                             //socket.connect(remoteAddr); et.getInputStream(); //Receive Data transcoding problem
  24. an Scanner in = New Scanner (IS);
  25. // Create a Printwriter object based on the established socket, and send the information to the server through this object.~                     out.println(str); ListAdapter_getvediourl_isConnected",socket.isConnected()+"");
  26.                                                                                    ; Hasnextline ())
  27. {
  28. result = in.nextline ();
  29. tempstr.append (result);
  30. system.out.println (tempstr); Intln ("Connection Service timeout");                                                                                                                                                                                                                      ​ ​ socket.close();//After completion. Turn off socket
  31. c //} Catch (socketexception e)
  32. // {
  33. // Return "--1";
  34. //system.out.println ("Connection failed");
  35. //e.printstacktrace ();                                      }catch(IOException e){
  36. //                                                                                                }
  37. }
  38. Copy code
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template