詳細講解Android的網絡通信(HttpUrlConnection和HttpClient)

前言,Android的網絡通信的方式有兩種:使用Socket或者HTTP,今天這一篇我們詳細講解使用HTTP實現的網絡通信,HTTP又包括兩種方式編程方式:

(1)HttpUrlConnection;

(2)HttpClient;

? ?好了,我們直接進行講解,當然之前也會有一部分有關Android網絡通信的其他知識,我們也應該了解。

?

一.獲取網絡狀態的方法

(1)MainActivity.java中的關鍵代碼

1
2
3
4
5
6
7
8
//網絡管理類,可以判斷是否能上網,以及網絡類型
????????????ConnectivityManager cm=(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
????????????NetworkInfo info=cm.getActiveNetworkInfo();
????????????if(info!=null){
????????????????Toast.makeText(MainActivity.this,?"連網正常"+info.getTypeName(), Toast.LENGTH_SHORT).show();
????????????}else{
????????????????Toast.makeText(MainActivity.this,?"未連網", Toast.LENGTH_SHORT).show();
????????????}

(2)注意:一定要在主配置文件中增加這個權限

? ?它是application的兄弟標簽:

1<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

(3)OK,我們看一下我們的設備的上網狀態和類型吧:

?

二.使用URL訪問網頁源碼

(1)MainActivity.java:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package?com.example.l0903_urldata;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?java.net.MalformedURLException;
import?java.net.URL;
import?android.app.Activity;
import?android.os.Bundle;
/**
?* 訪問網頁源碼
?* @author asus
?*
?*/
public?class?MainActivity?extends?Activity {
????@Override
????protected?void?onCreate(Bundle savedInstanceState) {
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????try?{
????????????//訪問百度的html文件的源碼
????????????InputStream is=new?URL("http://www.baidu.com").openStream();
????????????//讀取數據的包裝流
????????????BufferedReader br=new?BufferedReader(new?InputStreamReader(is));
????????????//str用于讀取一行數據
????????????String str=null;
????????????//StringBuffer用于存儲所欲數據
????????????StringBuffer sb=new?StringBuffer();
????????????while((str=br.readLine())!=null){
????????????????sb.append(str);
????????????}
????????????System.out.println(sb.toString());
????????}?catch?(MalformedURLException e) {
????????????e.printStackTrace();
????????}?catch?(IOException e) {
????????????e.printStackTrace();
????????}
????}
}

(2)注意:有關網絡的操作都需要在主配置文件里添加下面這個權限:

1<uses-permission android:name="android.permission.INTERNET"/>

?

三.WebView 控件的簡單使用

? ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package?com.example.l0903_webview;
import?android.app.Activity;
import?android.os.Bundle;
import?android.webkit.WebView;
/**
?* 就是一個瀏覽器控件
?* 其實沒什么用
?* @author asus
?*
?*/
public?class?MainActivity?extends?Activity {
????private?WebView wv;
????@Override
????protected?void?onCreate(Bundle savedInstanceState) {
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????wv=(WebView) findViewById(R.id.webView1);
????????//WebView控件的方法,loadUrl用于加載指定的網絡地址
????????wv.loadUrl("http://www.baidu.com");
????}
}

? ?運行效果:

?

四.使用HttpUrlConnection的編寫方式實現Android的網絡通信

1.首先,自己先搭建一個服務器:

?

?

2.下面是客戶端的事了:

(1)通過get方式:

? ?MainActivity.java:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package?com.example.l0903_httpurlcnectionget;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?java.net.HttpURLConnection;
import?java.net.MalformedURLException;
import?java.net.URL;
import?android.app.Activity;
import?android.os.Bundle;
import?android.view.View;
import?android.view.View.OnClickListener;
import?android.widget.EditText;
import?android.widget.TextView;
/**
?* 通過Get方法獲取服務器的數據
?* 直接在地址中用"?+鍵值+value"的方式來使用
?* 所以傳遞的參數直接顯示出來,不安全
?* @author asus
?*
?*/
public?class?MainActivity?extends?Activity {
????private?HttpURLConnection conn;
????private?URL url;
????private?InputStream is;
????private?TextView tv;
????private?EditText et;
????private?String name;
????@Override
????protected?void?onCreate(Bundle savedInstanceState) {
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????tv=(TextView) findViewById(R.id.textView1);
????????et=(EditText) findViewById(R.id.editText1);
????????findViewById(R.id.button1).setOnClickListener(new?OnClickListener() {
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????@Override
????????????public?void?onClick(View v) {
????????????????name=et.getText().toString();
????????????????//定義訪問的服務器地址,10.0.2.2是Android的訪問的本地服務器地址
????????????????String urlDate="http://10.0.2.2:8080/My_Service/webdate.jsp?name="+name;
????????????????try?{
????????????????????//封裝訪問服務器的地址
????????????????????url=new?URL(urlDate);
????????????????????try?{
????????????????????????//打開對服務器的連接
????????????????????????conn=(HttpURLConnection) url.openConnection();
????????????????????????//連接服務器
????????????????????????conn.connect();
????????????????????????/**讀入服務器數據的過程**/
????????????????????????//得到輸入流
????????????????????????is=conn.getInputStream();
????????????????????????//創建包裝流
????????????????????????BufferedReader br=new?BufferedReader(new?InputStreamReader(is));
????????????????????????//定義String類型用于儲存單行數據
????????????????????????String line=null;
????????????????????????//創建StringBuffer對象用于存儲所有數據
????????????????????????StringBuffer sb=new?StringBuffer();
????????????????????????while((line=br.readLine())!=null){
????????????????????????????sb.append(line);
????????????????????????}
????????????????????????//用TextView顯示接收的服務器數據
????????????????????????tv.setText(sb.toString());
????????????????????????System.out.println(sb.toString());
????????????????????}?catch?(IOException e) {
????????????????????????e.printStackTrace();
????????????????????}
????????????????}?catch?(MalformedURLException e) {
????????????????????e.printStackTrace();
????????????????}
????????????}
????????});
????}
}

? ?權限(同上面第二個,所有與網絡有關的操作都需要添加,下面的就不再贅述了)

? ?運行效果:

?

(2)通過post方式(安全)

MainActivity.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package?com.example.l0903_httpurlconectionpost;
import?java.io.BufferedReader;
import?java.io.DataOutputStream;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?java.io.OutputStream;
import?java.net.HttpURLConnection;
import?java.net.MalformedURLException;
import?java.net.URL;
import?java.net.URLEncoder;
import?android.app.Activity;
import?android.os.Bundle;
import?android.view.View;
import?android.view.View.OnClickListener;
import?android.widget.EditText;
import?android.widget.TextView;
/**
?* 通過Post方法傳遞參數
?* 安全
?* @author asus
?*
?*/
public?class?MainActivity?extends?Activity {
????private?HttpURLConnection conn;
????private?URL url;
????private?InputStream is;
????private?OutputStream os;
????private?EditText et;
????private?TextView tv;
????@Override
????protected?void?onCreate(Bundle savedInstanceState) {
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????et=(EditText) findViewById(R.id.editText1);
????????tv=(TextView) findViewById(R.id.tv);
????????findViewById(R.id.button1).setOnClickListener(new?OnClickListener() {
???????????????????????????????????????????????????????????????????????????????????
????????????@Override
????????????public?void?onClick(View v) {
????????????????// TODO Auto-generated method stub
????????????????String urlDate="http://10.0.2.2:8080/My_Service/webdate.jsp";
????????????????try?{
????????????????????url=new?URL(urlDate);
????????????????????try?{
????????????????????????//打開服務器
????????????????????????conn=(HttpURLConnection) url.openConnection();
????????????????????????//設置輸入輸出流
????????????????????????conn.setDoOutput(true);
????????????????????????conn.setDoInput(true);
????????????????????????//設置請求的方法為Post
????????????????????????conn.setRequestMethod("POST");
????????????????????????//Post方式不能緩存數據,則需要手動設置使用緩存的值為false
????????????????????????conn.setUseCaches(false);
????????????????????????//連接數據庫
????????????????????????conn.connect();
????????????????????????/**寫入參數**/
????????????????????????os=conn.getOutputStream();
????????????????????????//封裝寫給服務器的數據(這里是要傳遞的參數)
????????????????????????DataOutputStream dos=new?DataOutputStream(os);
????????????????????????//寫方法:name是key值不能變,編碼方式使用UTF-8可以用中文
????????????????????????dos.writeBytes("name="+URLEncoder.encode(et.getText().toString(),?"UTF-8"));
????????????????????????//關閉外包裝流
????????????????????????dos.close();
????????????????????????/**讀服務器數據**/
????????????????????????is=conn.getInputStream();
????????????????????????BufferedReader br=new?BufferedReader(new?InputStreamReader(is));
????????????????????????String line=null;
????????????????????????StringBuffer sb=new?StringBuffer();
????????????????????????while((line=br.readLine())!=null){
????????????????????????????sb.append(line);
????????????????????????}
????????????????????????tv.setText(sb.toString());
????????????????????????System.out.println(sb.toString());
????????????????????}?catch?(IOException e) {
????????????????????????e.printStackTrace();
????????????????????}
????????????????}?catch?(MalformedURLException e) {
????????????????????e.printStackTrace();
????????????????}
????????????}
????????});
???????????????????????????????????????????????????????????????????????????
????}
}

?

?

五.使用HttpClient的編寫方式實現Android的網絡通信

1.服務器同上;

2.使用get的方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package?com.example.l0903_http_get;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?org.apache.http.HttpEntity;
import?org.apache.http.HttpResponse;
import?org.apache.http.client.ClientProtocolException;
import?org.apache.http.client.HttpClient;
import?org.apache.http.client.methods.HttpGet;
import?org.apache.http.impl.client.DefaultHttpClient;
import?android.app.Activity;
import?android.os.Bundle;
public?class?MainActivity?extends?Activity {
????private?HttpGet get;
????private?HttpClient cliet;
????private?HttpResponse response;
????private?HttpEntity entity;
????private?InputStream is;
????@Override
????protected?void?onCreate(Bundle savedInstanceState) {
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????get=new?HttpGet("http://10.0.2.2:8080/My_Service/webdate.jsp?name=ooooooo");
????????cliet=new?DefaultHttpClient();
????????try?{
????????????response=cliet.execute(get);
????????????entity=response.getEntity();
????????????is=entity.getContent();
????????????BufferedReader br=new?BufferedReader(new?InputStreamReader(is));
????????????String line=null;
????????????StringBuffer sb=new?StringBuffer();
????????????while((line=br.readLine())!=null){
????????????????sb.append(line);
????????????}
????????????System.out.println(sb.toString());
????????}?catch?(ClientProtocolException e) {
????????????e.printStackTrace();
????????}?catch?(IOException e) {
????????????e.printStackTrace();
????????}
????????????????????????????????????????????????
????}
}

?

3.使用post的方式:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package?com.example.l0903_http_post;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?java.io.UnsupportedEncodingException;
import?java.util.ArrayList;
import?java.util.List;
import?org.apache.http.HttpEntity;
import?org.apache.http.HttpResponse;
import?org.apache.http.client.ClientProtocolException;
import?org.apache.http.client.HttpClient;
import?org.apache.http.client.entity.UrlEncodedFormEntity;
import?org.apache.http.client.methods.HttpPost;
import?org.apache.http.impl.client.DefaultHttpClient;
import?org.apache.http.message.BasicNameValuePair;
import?android.app.Activity;
import?android.os.Bundle;
public?class?MainActivity?extends?Activity {
????//創建請求對象
????private?HttpPost post;
????//創建客戶端對象
????private?HttpClient cliet;
????//創建發送請求的對象
????private?HttpResponse response;
????//
????private?UrlEncodedFormEntity urlEntity;
????//創建接收返回數據的對象
????private?HttpEntity entity;
????//創建流對象
????private?InputStream is;
????@Override
????protected?void?onCreate(Bundle savedInstanceState) {
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????//包裝請求的地址
????????post=new?HttpPost("http://10.0.2.2:8080/My_Service/webdate.jsp");
????????//創建默認的客戶端對象
????????cliet=new?DefaultHttpClient();
????????//用list封裝要向服務器端發送的參數
????????List<BasicNameValuePair> pairs=new?ArrayList<BasicNameValuePair>();
????????pairs.add(new?BasicNameValuePair("name",?"llllllllll"));
????????try?{
????????????//用UrlEncodedFormEntity來封裝List對象
????????????urlEntity=new?UrlEncodedFormEntity(pairs);
????????????//設置使用的Entity
????????????post.setEntity(urlEntity);
????????????try?{
????????????????//客戶端開始向指定的網址發送請求
????????????????response=cliet.execute(post);
????????????????//獲得請求的Entity
????????????????entity=response.getEntity();
????????????????is=entity.getContent();
????????????????//下面是讀取數據的過程
????????????????BufferedReader br=new?BufferedReader(new?InputStreamReader(is));
????????????????String line=null;
????????????????StringBuffer sb=new?StringBuffer();
????????????????while((line=br.readLine())!=null){
????????????????????sb.append(line);
????????????????}
????????????????System.out.println(sb.toString());
????????????}?catch?(ClientProtocolException e) {
????????????????e.printStackTrace();
????????????}?catch?(IOException e) {
????????????????e.printStackTrace();
????????????}
????????}?catch?(UnsupportedEncodingException e) {
????????????e.printStackTrace();
????????}
?????????????????????????????????????????????
?????????????????????????????????????????????
????}
}

?

4.實現HttpClient通信與AsyncTask異步機制的結合:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package?com.example.l0903_http_asynctask_get;
import?java.io.BufferedReader;
import?java.io.IOException;
import?java.io.InputStream;
import?java.io.InputStreamReader;
import?org.apache.http.HttpEntity;
import?org.apache.http.HttpResponse;
import?org.apache.http.client.ClientProtocolException;
import?org.apache.http.client.HttpClient;
import?org.apache.http.client.methods.HttpGet;
import?org.apache.http.impl.client.DefaultHttpClient;
import?android.app.Activity;
import?android.app.ProgressDialog;
import?android.os.AsyncTask;
import?android.os.Bundle;
import?android.widget.TextView;
/**
?*
?* @author asus
?*
?*/
public?class?MainActivity?extends?Activity {
????private?TextView tv;// 創建請求對象
????private?HttpGet httpGet;
????// 創建客戶端對象
????private?HttpClient httpClient;
????// 發送請求的對象
????private?HttpResponse httpResponse;
????// 接收返回數據
????private?HttpEntity httpEntity;
????// 創建流
????private?InputStream in;
????private?ProgressDialog pd;
????@Override
????protected?void?onCreate(Bundle savedInstanceState) {
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????tv = (TextView) findViewById(R.id.tv);
????????AsyncTask<String, Void, String> asyncTask =?new?AsyncTask<String, Void, String>() {
????????????@Override
????????????protected?String doInString...? params) {
????????????????String urlstr = params[0];
????????????????httpGet =?new?HttpGet(urlstr);
????????????????httpClient =?new?DefaultHttpClient();
????????????????try?{
????????????????????// 向服務器端發送請求
????????????????????httpResponse = httpClient.execute(httpGet);
????????????????????httpEntity = httpResponse.getEntity();
????????????????????in = httpEntity.getContent();
????????????????????BufferedReader br =?new?BufferedReader(
????????????????????????????new?InputStreamReader(in));
????????????????????String line =?null;
????????????????????StringBuffer sb =?new?StringBuffer();
????????????????????while?((line = br.readLine()) !=?null) {
????????????????????????sb.append(line);
????????????????????}
????????????????????System.out.println(sb.toString());
????????????????????return?sb.toString();
????????????????}?catch?(ClientProtocolException e) {
????????????????????e.printStackTrace();
????????????????}?catch?(IOException e) {
????????????????????e.printStackTrace();
????????????????}
????????????????return?null;
????????????}
????????????@Override
????????????protected?void?onPostExecute(String result) {
????????????????if?(result !=?null) {
????????????????????tv.setText(result);
????????????????????pd.dismiss();// 消除dialog
????????????????}
????????????????super.onPostExecute(result);
????????????}
????????};
????????pd = ProgressDialog.show(this,?"請稍后。。。",?"正在請求數據");
????????asyncTask.execute("http://10.0.2.2:8080/My_Service/webdate.jsp?name=haha&age=hh");
????}
}

運行效果:

?

轉載于:https://www.cnblogs.com/AceIsSunshineRain/p/5095137.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/272506.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/272506.shtml
英文地址,請注明出處:http://en.pswp.cn/news/272506.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

常見通信協議HTTP、TCP、UDP的簡單介紹

TCP HTTP UDP:都是通信協議&#xff0c;也就是通信時所遵守的規則&#xff0c;只有雙方按照這個規則“說話”&#xff0c;對方才能理解或為之服務。TCP HTTP UDP三者的關系:TCP/IP是個協議組&#xff0c;可分為四個層次&#xff1a;網絡接口層、網絡層、傳輸層和應用層…

創建進程相關函數

fork函數 pid_t fork(void); fork函數調用成功&#xff0c; 返回兩次 在fork函數執行完畢后 如果創建新進程成功&#xff0c;則出現兩個進程 一個是子進程&#xff0c;一個是父進程 在子進程中&#xff0c;fork函數返回0 在父進程中&#xff0c;fork返回新創建子進程的進程ID…

實現Windows和Linux之間的文件共享

一、windows 向linux共享文件(這里都是以win10和ubuntu為例)首先&#xff0c;打開網絡共享中心。如圖1圖1打開更改高級共享設置&#xff08;圖2&#xff09;圖 2選擇啟用網絡發現以及啟用文件和打印機共享&#xff0c;然后點擊保存更改。接著&#xff0c;選擇你要共享的文件夾&…

雞啄米MFC教程筆記之七:對話框:為控件添加消息處理函數

MFC為對話框和控件等定義了諸多消息&#xff0c;我們對它們操作時會觸發消息&#xff0c;這些消息最終由消息處理函數處理。比如我們點擊按鈕時就會產生BN_CLICKED消息&#xff0c;修改編輯框內容時會產生EN_CHANGE消息等。一般為了讓某種操作達到效果&#xff0c;我們只需要實…

進程的退出方式以及僵尸進程和孤兒進程

&#xff08;1&#xff09;正常退出 &#xff08;2&#xff09;異常退出 檢查wait和waitpid所返回的終止狀態的宏 宏說明WIFEXITED(status)若為正常終止子進程返回的狀態&#xff0c;則為真。對于這種情況可執行WEXITSTATUS(status)&#xff0c;取子進程傳送給exit、_exit或_…

java中的動態代理----自己手動實現

代碼使用了common-io&#xff0c;需要其jar 1 接口 Java代碼 public interface Pruduct { void selling(); } 2 書籍類 Java代碼 public class Book implements Pruduct { Override public void selling() { try { Thread.sleep(1000…

Code Project精彩系列(1)

ApplicationsCrafting a C# forms Editor From scratchhttp://www.codeproject.com/csharp/SharpFormEditorDemo.asp建立一個類似C#的環境, 實現控件拖拉&#xff0c;屬性Packet Capture and Analayzer網絡封包截獲http://www.codeproject.com/csharp/pacanal.aspA tool to cha…

linux進程---exec族函數(execl, execlp, execv, execvp, )解釋和配合fork的使用

exec族函數函數的作用&#xff1a; exec函數族的作用是根據指定的文件名找到可執行文件&#xff0c;并用它來取代調用進程的內容&#xff0c;換句話說&#xff0c;就是在調用進程內部執行一個可執行文件。這里的可執行文件既可以是二進制文件&#xff0c;也可以是任何L…

Code Project精彩系列(2)

Windows FormsFireball Resourcer把各種資源嵌入應用程序資源Window Hiding with C#隱藏窗體, 似乎是其它運行的窗體 JProper Threading in Winforms .NETWindows Forms User Settings in C#使用VS設置設定forms, coolA Pretty Good Splash Screen in C#一個自繪可愛屏幕A curt…

python bool值要注意的一些地方

1、像(),[],{}這三個是可以通過bool(()),bool([]),bool({})轉化為bool值的&#xff1b;且它們轉化后的結果為False。但是這三個值它本身并不等于False、切記不可以與False 直接進行比較。 #!/usr/bin/python #!coding:utf-8 import sysif __name__ "__main__":falseL…

system函數和popen函數使用方法

system int system(const char *command);system&#xff08;&#xff09;函數的返回值如下&#xff1a; 成功&#xff0c;則返回進程的狀態值&#xff1b; 當sh不能執行時&#xff0c;返回127&#xff1b; 失敗返回-1&#xff1b; 其實是封裝后的exec&#xff0c;函數源代碼在…

前端必備知識點—SVG

基本內容什么是SVG? 全稱為Scalable Vector Graphics&#xff0c;是一種使用XML技術描述二維圖形的語言&#xff0c;簡單來說 - 矢量圖(不失真)SVG與HTML5的關系早在HTML5之前,存在SVG技術SVG文件擴展名為".svg"在HTML5出現之前,要在HTML頁面中引入SVG文件在HTML5出…

CocoaPods安裝和使用及問題:Setting up CocoaPods master repo

CocoaPods是什么&#xff1f; 當你開發iOS應用時&#xff0c;會經常使用到很多第三方開源類庫&#xff0c;比如JSONKit&#xff0c;AFNetWorking等等。可能某個類庫又用到其他類庫&#xff0c;所以要使用它&#xff0c;必須得另外下載其他類庫&#xff0c;而其他類庫又用到其他…

進程間的通信IPC(無名管道和命名管道)

進程間的通信IPC介紹 進程間通信&#xff08;IPC&#xff0c;InterProcess Communication&#xff09;是指在不同進程之間傳播或交換信息。 IPC的方式通常有管道&#xff08;包括無名管道和命名管道&#xff09;、消息隊列、信號量、共享存儲、Socket、Streams等。其中 Socket…

那些關于瀏覽器的趣圖和幽默段子

1、當瀏覽器化作一種槍&#xff0c;你喜歡用哪種呢&#xff1f;2、這神奇的反射弧&#xff0c;有點長…3、瀏覽器們成長的煩惱4、這么說來&#xff0c;IE瀏覽器扳回一分&#xff01;5、如何用瀏覽器區分 HTML和 HTML56、都在吹牛&#xff0c;還是IE最務實&#xff01;7、主流瀏…

前端新手程序員不知道的 20個小技巧

1.作為前端開發者&#xff0c;使用雙顯示器能大幅提高開發效率。2.學編程最好的語言不是PHP&#xff0c;是English。3.東西交付之前偷偷測試一遍。4.問別人之前最好先自己百度&#xff0c;google一下&#xff0c;以免問出太低級的問題。5.把覺得不靠譜的需求放到最后做&#xf…

IPC 共享內存和 消息隊列(發送、接收、移除)以及鍵值的生成

一、消息對列 消息隊列&#xff0c;是消息的鏈接表&#xff0c;存放在內核中。一個消息隊列由一個標識符&#xff08;即隊列ID&#xff09;來標識。 特點&#xff1a; 消息隊列是面向記錄的&#xff0c;其中的消息具有特定的格式以及特定的優先級。消息隊列獨立于發送與接收進…

DBA十大必備工具(SQLServer)

曾經和一些DBA和數據庫開發人員交流時&#xff0c;問他們都用過一些什么樣的DB方面的工具&#xff0c;大部分人除了SSMS和Profile之外&#xff0c;基本就沒有使用過其他工具了&#xff1b;誠然&#xff0c;SSMS和Profile足夠強大&#xff0c;工作的大部分內容都能通過它們搞定&…

linux 信號和信號量編程

對于 Linux來說&#xff0c;實際信號是軟中斷&#xff0c;許多重要的程序都需要處理信號。信號&#xff0c;為 Linux 提供了一種處理異步事件的方法。比如&#xff0c;終端用戶輸入了 ctrlc 來中斷程序&#xff0c;會通過信號機制停止一個程序。 信號概述 信號的名字和編號&…

安卓動畫基礎講解

//逐幀動畫 /** * 1.加入單張圖片 * 2.生成movie.xml整個圖片 * 3.代碼中使用圖片movie.xml */ iv(ImageView) findViewById(R.id.iv);// iv.setImageResource(R.drawable.movie);//為iv加載六張圖片// AnimationDrawable ad(AnimationDrawable) iv.getDrawable();//得到圖片給…