国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Android網(wǎng)絡(luò)功能開發(fā)(6)——TCP協(xié)議通信

這篇具有很好參考價值的文章主要介紹了Android網(wǎng)絡(luò)功能開發(fā)(6)——TCP協(xié)議通信。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

TCP通信的雙方需要建立連接,所以先由一方監(jiān)聽某個端口,等待其他設(shè)備來連接,這一方稱為服務(wù)器端。另一方向服務(wù)器端發(fā)起連接請求,稱為客戶端。服務(wù)器端接受客戶端的連接請求后,雙方之間的連接建立起來。連接建立后,雙方對于連接的使用是相同的,都可以通過連接發(fā)送和接收數(shù)據(jù)。

Android網(wǎng)絡(luò)功能開發(fā)(6)——TCP協(xié)議通信

如果雙方通信時沒有像HTTP協(xié)議這種一問一答的固定模式,就需要隨時接收和處理對方發(fā)來的數(shù)據(jù),所以要把接收和處理數(shù)據(jù)的工作在一個單獨的線程中執(zhí)行。如果服務(wù)器端想同時與多個客戶端通信,要對每個客戶端的連接建立一個接收線程。

下面通過一個簡單的聊天室原型來演示如何編程實現(xiàn)TCP通信。聊天室系統(tǒng)包含一個服務(wù)器和多個客戶端。服務(wù)器對從一個客戶端接收的信息,要轉(zhuǎn)發(fā)到所有客戶端??蛻舳艘褟姆?wù)器接收的信息顯示給用戶,并把用戶輸入的信息發(fā)送到服務(wù)器。為實現(xiàn)這一功能,系統(tǒng)的結(jié)構(gòu)要像下面這個圖這樣設(shè)計。

Android網(wǎng)絡(luò)功能開發(fā)(6)——TCP協(xié)議通信

聊天服務(wù)器端有一個TCP監(jiān)聽線程,當(dāng)有客戶端發(fā)來連接請求時,負(fù)責(zé)接受客戶端的連接請求并創(chuàng)建接收線程。同時,用一個列表記下所有的客戶端連接。這樣,接收線程就能夠?qū)⒔邮盏降男畔l(fā)往列表中保存的所有客戶端??蛻舳艘灿袃蓚€線程,接收線程負(fù)責(zé)從服務(wù)器接收數(shù)據(jù)并顯示給用戶,主線程接收用戶的輸入并發(fā)往服務(wù)器。

服務(wù)器端運行在JavaSE上,的具體代碼是這樣的:

Android網(wǎng)絡(luò)功能開發(fā)(6)——TCP協(xié)議通信

監(jiān)聽線程ListeningThread首先創(chuàng)建一個ServerSocket對象,然后循環(huán)調(diào)用它的accept方法等待接受客戶端的連接請求。當(dāng)有客戶端發(fā)來連接請求時,accept方法返回一個Socket對象。監(jiān)聽線程把Socket對象添加到連接列表connections,并創(chuàng)建一個接收線程ServiceThread。

接收線程循環(huán)調(diào)用readLine,一旦客戶端有消息發(fā)來,readLine就會返回發(fā)來的消息內(nèi)容,然后調(diào)用chatMessage發(fā)送到所有客戶端(包括自己)。

chatMessage方法遍歷客戶端列表connections,把客戶端發(fā)來的消息轉(zhuǎn)發(fā)到所有客戶端。

客戶端是一個Android應(yīng)用,界面是這樣的:最上面一行文本框中輸入服務(wù)器的IP地址;下面TCP一行的三個按鈕控制建立連接、發(fā)送信息、斷開連接;再下面UDP一行三個按鈕用于測試UDP通信方式;再下面的Content文本框是要發(fā)送的聊天消息;最下面的文本是所有聊天內(nèi)容。

Android網(wǎng)絡(luò)功能開發(fā)(6)——TCP協(xié)議通信

當(dāng)點擊TCP的Connect按鈕時,以服務(wù)器端的IP地址和端口號為參數(shù)創(chuàng)建一個Socket對象,這樣就會向服務(wù)器發(fā)送一個建立連接的請求。如果服務(wù)器接受請求,那么連接就成功建立,Socket對象也會創(chuàng)建成功,否則會產(chǎn)生異常,轉(zhuǎn)入異常處理流程。

有了Socket對象后,接著創(chuàng)建一個接收數(shù)據(jù)的線程。注意這部分代碼也需要用AsyncTask異步執(zhí)行,不能占用主線程。接收線程中循環(huán)調(diào)用in.readLine方法不斷讀取服務(wù)器發(fā)來的消息,一旦有消息發(fā)過來,該方法就會返回消息內(nèi)容。接著再調(diào)用sendMessage把消息內(nèi)容傳給主線程顯示,因為子線程中不能直接操作界面控件。

傳遞消息內(nèi)容用的Android的Handler機制,主線程中創(chuàng)建一個Handler對象,并在它的handleMessage方法中接收消息。子線程中調(diào)用該Handler對象的sendMessage方法傳遞消息。這樣就能在線程間傳遞消息了。

當(dāng)點擊TCP的Send按鈕時,代碼是把Content文本框中的字符串通過Socket連接發(fā)送到服務(wù)器。

Android端的布局文件如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:text="Server:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        app:layout_constraintEnd_toStartOf="@+id/editTextServer"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/editTextServer"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10"
        app:layout_constraintBaseline_toBaselineOf="@+id/textView1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/textView1">

        <requestFocus
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:text="TCP: "
        android:textAppearance="?android:attr/textAppearanceLarge"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/buttonTCPConnect" />

    <Button
        android:id="@+id/buttonTCPConnect"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Connect"
        android:textAllCaps="false"
        app:layout_constraintBaseline_toBaselineOf="@+id/buttonTCPSend"
        app:layout_constraintStart_toEndOf="@+id/textView2" />

    <Button
        android:id="@+id/buttonTCPSend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        android:layout_marginLeft="10dp"
        android:text="Send"
        android:textAllCaps="false"
        app:layout_constraintStart_toStartOf="@+id/buttonUDPSend"
        app:layout_constraintTop_toBottomOf="@+id/editTextServer" />

    <Button
        android:id="@+id/buttonTCPClose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Close"
        android:textAllCaps="false"
        app:layout_constraintBaseline_toBaselineOf="@+id/buttonTCPSend"
        app:layout_constraintStart_toEndOf="@+id/buttonTCPSend" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="6dp"
        android:text="UDP:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/buttonUDPListen" />

    <Button
        android:id="@+id/buttonUDPListen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Listen"
        android:textAllCaps="false"
        app:layout_constraintBaseline_toBaselineOf="@+id/buttonUDPSend"
        app:layout_constraintStart_toEndOf="@+id/textView3" />

    <Button
        android:id="@+id/buttonUDPSend"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Send"
        android:textAllCaps="false"
        app:layout_constraintStart_toEndOf="@+id/buttonUDPListen"
        app:layout_constraintTop_toBottomOf="@+id/buttonTCPConnect" />

    <Button
        android:id="@+id/buttonUDPStop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Stop"
        android:textAllCaps="false"
        app:layout_constraintBaseline_toBaselineOf="@+id/buttonUDPSend"
        app:layout_constraintStart_toEndOf="@+id/buttonUDPSend" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Content:"
        android:textAppearance="?android:attr/textAppearanceLarge"
        app:layout_constraintBaseline_toBaselineOf="@+id/editTextContent"
        app:layout_constraintStart_toStartOf="parent" />

    <EditText
        android:id="@+id/editTextContent"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/textView4"
        app:layout_constraintTop_toBottomOf="@+id/buttonUDPListen" />

    <TextView
        android:id="@+id/textViewResult"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editTextContent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Android端的完整代碼如下:

import androidx.appcompat.app.AppCompatActivity;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;

public class MainActivity extends AppCompatActivity {
    EditText etServer;
    EditText etContent;
    TextView tvResult;

    Handler mHandler;

    Socket tcpSocket;
    TCPReceiveThread tcpReceiveThread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        etServer = findViewById(R.id.editTextServer);
        etContent = findViewById(R.id.editTextContent);
        tvResult = findViewById(R.id.textViewResult);

        etServer.setText("192.168.1.2");

        tcpSocket = null;
        mHandler = new Handler(){
            @Override
            public void handleMessage(Message msg){
                switch(msg.what) {
                    case 1:	// receive socket message
                        String received = (String)msg.obj;
                        tvResult.append(received+"\r\n");
                        break;
                }
            }
        };

        Button btnTCPConnect = findViewById(R.id.buttonTCPConnect);
        btnTCPConnect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                String serverIP = etServer.getText().toString();
                // tcpConnect(serverIP);	// 不能在主線程中執(zhí)行網(wǎng)絡(luò)操作
                new AsyncTask<String, Void, Void>(){
                    @Override
                    protected Void doInBackground(String... arg0) {
                        try {
                            tcpConnect(arg0[0]);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        return null;
                    }
                }.execute(serverIP);
            }
        });

        Button btnTCPSend = findViewById(R.id.buttonTCPSend);
        btnTCPSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                new AsyncTask<String, Void, Void>(){
                    @Override
                    protected Void doInBackground(String... arg0) {
                        try {
                            tcpSend(arg0[0]);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        return null;
                    }
                }.execute(etContent.getText().toString());
                etContent.setText("");
            }
        });

        Button btnTCPClose = (Button) findViewById(R.id.buttonTCPClose);
        btnTCPClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                new AsyncTask<Void, Void, Void>(){
                    @Override
                    protected Void doInBackground(Void... arg0) {
                        try {
                            tcpDisconnect();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        return null;
                    }
                }.execute();
            }
        });

    }
    void tcpConnect(String ip) throws IOException {
        if(tcpSocket!=null) tcpDisconnect();
        tcpSocket = new Socket(ip, 8899);
        tcpSocket.setSoTimeout(1000);
        tcpReceiveThread = new TCPReceiveThread();
        tcpReceiveThread.start();
    }

    void tcpSend(String ctx) throws IOException {
        ctx += "\r\n";
        byte[] buf = ctx.getBytes("UTF-8");
        tcpSocket.getOutputStream().write(buf);
    }

    void tcpDisconnect() throws IOException {
        if(tcpReceiveThread!=null)
            tcpReceiveThread.setStopFlag();	// 具體的關(guān)閉操作在接收線程結(jié)束后執(zhí)行,
    }

    void sendMessage(String str){
        Message msg = Message.obtain();	// 從Message池中取Message對象,用new創(chuàng)建會用到內(nèi)存分配,影響效率
        msg.what = 1;
        msg.obj = str;
        mHandler.sendMessage(msg);
    }

    class TCPReceiveThread extends Thread {
        private boolean flag;

        public void setStopFlag(){
            flag = false;
        }

        @Override
        public void run(){
            try {
                flag = true;
                BufferedReader in = new BufferedReader(new InputStreamReader(tcpSocket.getInputStream(), "UTF-8"));
                sendMessage("TCP socket connection connected");
                String line = null;
                while(flag) {
                    try {
                        line = in.readLine();
                    } catch (SocketTimeoutException e){
                        //e.printStackTrace();
                        //flag = false;
                    }
                    if(line != null) {
                        System.out.println(line);
                        sendMessage(line);
                        line = null;
                    }
                }
                in.close();
                tcpSocket.close();
                tcpSocket = null;
                sendMessage("TCP socket connection closed");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}

Server端在JavaSE平臺上實現(xiàn),完整代碼如下:

import java.io.*;
import java.net.*;
import java.util.*;

public class ChatServer {
	public static void main(String[] args){
		Thread listeningThread = new ListeningThread(8899);
		listeningThread.start();
	}
}
class ListeningThread extends Thread {
	private int port;
	private boolean flag = true;
	private ServerSocket lServerSocket;
	private List<PrintWriter> connections = new Vector<PrintWriter>();	//保存所有連結(jié)
	public ListeningThread(int aPort){
		port = aPort;
	}
	public void run(){
		try {
			lServerSocket = new ServerSocket(port);
			lServerSocket.setSoTimeout(1000);
			System.out.println("TCP Socket Start listening......");
			while(flag) {
				try {
					Socket incoming = lServerSocket.accept();
					System.out.println("Accept "+incoming.getInetAddress()+"("+incoming.getPort()+")");
					//PrintWriter out = new PrintWriter(incoming.getOutputStream(),true);
					PrintWriter out = new PrintWriter(new OutputStreamWriter(incoming.getOutputStream(), "UTF-8"),true);
					connections.add(out);	//有新連結(jié)則將其輸出流添加到連結(jié)列表中
					out.println("Welcome to "+lServerSocket.getInetAddress()+"("+lServerSocket.getLocalPort()+")");	
					out.flush();
					Thread t = new ServiceThread(incoming);	//啟動接收數(shù)據(jù)線程
					t.start();
				}
				catch(SocketTimeoutException e) {
					if(!flag)break;
				}
			}
			lServerSocket.close();
			System.exit(0);
		}
		catch(IOException e) {
			System.out.println(e);
		}
	}
	public synchronized void chatMessage(String msg) {
		Iterator<PrintWriter> iter = connections.iterator();
		while(iter.hasNext()) {
			try {
				PrintWriter out = iter.next();
				out.println(msg);
				out.flush();
			}
			catch(Exception e) {
				iter.remove();	//如果發(fā)送中出現(xiàn)異常,則將連結(jié)移除
			}
		}
	}
	class ServiceThread extends Thread {
		private Socket lSocket;
		public ServiceThread(Socket aSocket){
			lSocket = aSocket;
		}
		public void run(){
			try {
				BufferedReader in = new BufferedReader(new InputStreamReader(lSocket.getInputStream(), "UTF-8"));
				String line;
				while(flag){
					line = in.readLine();
					if(line != null){
						System.out.println(line);	// 本地屏幕顯示
						chatMessage("Chat:"+line);	// 發(fā)送到所有客戶端
					}
				}
				lSocket.close();
				System.out.println("Thread stoped.");
			}
			catch(IOException e){
				System.out.println(e);
			}
		}
	}
}

完整代碼下載:

?Android網(wǎng)絡(luò)功能開發(fā)-Socket編程接口使用的例子文章來源地址http://www.zghlxwxcb.cn/news/detail-484135.html

到了這里,關(guān)于Android網(wǎng)絡(luò)功能開發(fā)(6)——TCP協(xié)議通信的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【網(wǎng)絡(luò)編程】網(wǎng)絡(luò)通信基礎(chǔ)——簡述TCP/IP協(xié)議

    【網(wǎng)絡(luò)編程】網(wǎng)絡(luò)通信基礎(chǔ)——簡述TCP/IP協(xié)議

    個人主頁:兜里有顆棉花糖 歡迎 點贊?? 收藏? 留言? 加關(guān)注??本文由 兜里有顆棉花糖 原創(chuàng) 收錄于專欄【網(wǎng)絡(luò)編程】【Java系列】 本專欄旨在分享學(xué)習(xí)網(wǎng)絡(luò)編程的一點學(xué)習(xí)心得,歡迎大家在評論區(qū)交流討論?? ip地址簡單來說就是用來描述網(wǎng)絡(luò)上一個設(shè)備的所在位置。 端

    2024年02月04日
    瀏覽(36)
  • 【Java】--網(wǎng)絡(luò)編程:基于TCP協(xié)議的網(wǎng)絡(luò)通信

    【Java】--網(wǎng)絡(luò)編程:基于TCP協(xié)議的網(wǎng)絡(luò)通信

    TCP協(xié)議(Transmission Control Protocol),即傳輸控制協(xié)議,是一種 面向連接 的, 可靠 的,基于 字節(jié)流 的傳輸層通信協(xié)議。數(shù)據(jù)大小無限制。 建立連接的過程需要 三次握手 。 斷開連接的過程需要 四次揮手 。 使用TCP協(xié)議的通信雙方分別為 客戶端 和 服務(wù)器端 。 客戶端負(fù)責(zé)向服務(wù)

    2024年01月23日
    瀏覽(41)
  • 深入理解網(wǎng)絡(luò)通信和TCP、IP協(xié)議-01

    深入理解網(wǎng)絡(luò)通信和TCP、IP協(xié)議-01

    計算機網(wǎng)絡(luò)是什么? 隨著計算機技術(shù)發(fā)展,計算機的體積和價格都在下降,之前計算機多用于研究機構(gòu),現(xiàn) 階段逐步進(jìn)入一般的公司用于辦公。原來計算機之間傳輸數(shù)據(jù)需要通過軟盤等第三方存儲介 質(zhì)進(jìn)行轉(zhuǎn)存,人們需要將數(shù)據(jù)直接通過通信線路傳輸,來縮短傳輸時間,于

    2024年02月16日
    瀏覽(26)
  • WebSocket | 基于TCP的全雙工通信網(wǎng)絡(luò)協(xié)議

    WebSocket | 基于TCP的全雙工通信網(wǎng)絡(luò)協(xié)議

    ???作者介紹:雙非本科大三網(wǎng)絡(luò)工程專業(yè)在讀,阿里云專家博主,專注于Java領(lǐng)域?qū)W習(xí),擅長web應(yīng)用開發(fā)、數(shù)據(jù)結(jié)構(gòu)和算法,初步涉獵Python人工智能開發(fā)和前端開發(fā)。 ??主頁:@逐夢蒼穹 ??所屬專欄:Java EE ? 您的一鍵三連,是我創(chuàng)作的最大動力?? WebSocket 是基于 TCP 的一

    2024年02月19日
    瀏覽(28)
  • 深入理解TCP/IP協(xié)議:網(wǎng)絡(luò)通信的基石

    深入理解TCP/IP協(xié)議:網(wǎng)絡(luò)通信的基石

    提示:本系列文章重點學(xué)習(xí)TCP/IP協(xié)議 提示:在這里先對TCP/IP協(xié)議做一個概述,以便大家能更好的理解: TCP/IP協(xié)議是當(dāng)今互聯(lián)網(wǎng)世界中最為重要的網(wǎng)絡(luò)通信協(xié)議之一,它承載了全球范圍內(nèi)數(shù)以億計的設(shè)備之間的通信。無論是在個人日常使用的智能手機,還是在企業(yè)級的網(wǎng)絡(luò)架

    2024年04月16日
    瀏覽(25)
  • linux【網(wǎng)絡(luò)編程】TCP協(xié)議通信模擬實現(xiàn)、日志函數(shù)模擬、守護(hù)進(jìn)程化、TCP協(xié)議通信流程、三次握手與四次揮手

    linux【網(wǎng)絡(luò)編程】TCP協(xié)議通信模擬實現(xiàn)、日志函數(shù)模擬、守護(hù)進(jìn)程化、TCP協(xié)議通信流程、三次握手與四次揮手

    Tcp通信模擬實現(xiàn)與Udp通信模擬實現(xiàn)的區(qū)別不大,一個是面向字節(jié)流,一個是面向數(shù)據(jù)報;udp協(xié)議下拿到的數(shù)據(jù)可以直接發(fā)送,tcp協(xié)議下需要創(chuàng)建鏈接,用文件描述符完成數(shù)據(jù)的讀寫 1.1.1 接口認(rèn)識 1.1.1.1 listen:監(jiān)聽socket 1.1.1.2 accept:獲取連接 通信就用accept返回的文件描述符,

    2024年02月06日
    瀏覽(29)
  • 【網(wǎng)絡(luò)】socket——TCP網(wǎng)絡(luò)通信 | 日志功能 | 守護(hù)進(jìn)程

    【網(wǎng)絡(luò)】socket——TCP網(wǎng)絡(luò)通信 | 日志功能 | 守護(hù)進(jìn)程

    ??作者:一只大喵咪1201 ??專欄:《網(wǎng)絡(luò)》 ??格言: 你只管努力,剩下的交給時間! 上篇文章中本喵介紹了UDP網(wǎng)絡(luò)通信的socket代碼,今天介紹TCP網(wǎng)絡(luò)通信的socket代碼。 和 udp 的網(wǎng)絡(luò)通信一樣, tcp 通信也需要服務(wù)器指定端口號,IP地址同樣使用 0.0.0.0 ,以便客戶端所有對服

    2024年02月16日
    瀏覽(24)
  • socket套接字通信 TCP傳輸控制協(xié)議/IP網(wǎng)絡(luò)協(xié)議 5.18

    socket套接字通信 TCP傳輸控制協(xié)議/IP網(wǎng)絡(luò)協(xié)議 5.18

    B/S :瀏覽器和服務(wù)器 C/S :客戶機和服務(wù)器 網(wǎng)絡(luò)的層次結(jié)構(gòu)和每層所使用協(xié)議的集合 網(wǎng)絡(luò)采用分層管理的方法,將網(wǎng)絡(luò)的功能劃分為不同的模塊 OSI模型: 共7種: 數(shù)據(jù)的封裝與傳遞過程: 網(wǎng)絡(luò)傳輸數(shù)據(jù)大小user data: 6~1460 網(wǎng)絡(luò)傳輸中容易發(fā)生拆包和粘包,所以接收和發(fā)送的字節(jié)

    2024年02月05日
    瀏覽(31)
  • 網(wǎng)絡(luò)編程day2——基于TCP/IP協(xié)議的網(wǎng)絡(luò)通信

    ? ? ? ? 計算機S ? ? ? ? ? ? ? ? ? ? ? ? ????????????????????????計算機C ? ? ?創(chuàng)建socket對象 ? ? ? ? ? ? ? ? ????????????????? 創(chuàng)建socket對象 ? ? ?準(zhǔn)備通信地址(自己的ip(非公網(wǎng)ip))? ? ? 準(zhǔn)備通信地址 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (計算

    2024年02月10日
    瀏覽(40)
  • 【計網(wǎng)】TCP協(xié)議安全與風(fēng)險:深入探討網(wǎng)絡(luò)通信的基石

    【計網(wǎng)】TCP協(xié)議安全與風(fēng)險:深入探討網(wǎng)絡(luò)通信的基石

    ?? ?? 個人博客: 個人主頁 ?? 個人專欄: Linux ???? 功不唐捐,玉汝于成 目錄 ??前言 ??正文 TCP (Transmission Control Protocol): UDP (User Datagram Protocol): HTTP (Hypertext Transfer Protocol): HTTPS (Hypertext Transfer Protocol Secure): ??結(jié)語 ?我的其他博客 TCP(傳輸控制協(xié)議)是計算機網(wǎng)絡(luò)中最

    2024年03月10日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包