女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

鴻蒙開(kāi)發(fā)實(shí)戰(zhàn):【網(wǎng)絡(luò)管理-Socket連接】

jf_46214456 ? 來(lái)源:jf_46214456 ? 作者:jf_46214456 ? 2024-03-19 22:04 ? 次閱讀

介紹

本示例主要演示了Socket在網(wǎng)絡(luò)通信方面的應(yīng)用,展示了Socket在兩端設(shè)備的連接驗(yàn)證、聊天通信方面的應(yīng)用。

效果預(yù)覽

image.png

使用說(shuō)明

1.打開(kāi)應(yīng)用,點(diǎn)擊用戶文本框選擇要登錄的用戶,并輸入另一個(gè)設(shè)備的IP地址,點(diǎn)擊確定按鈕進(jìn)入已登錄的用戶頁(yè)面(兩個(gè)設(shè)備都要依次執(zhí)行此步驟)。

2.在其中一個(gè)設(shè)備上點(diǎn)擊創(chuàng)建房間按鈕,任意輸入房間號(hào),另一個(gè)設(shè)備會(huì)收到有房間號(hào)信息的彈框,點(diǎn)擊確定按鈕后,兩個(gè)設(shè)備進(jìn)入聊天頁(yè)面。

3.在其中一個(gè)設(shè)備上輸入聊天信息并點(diǎn)擊發(fā)送按鈕后,另一個(gè)設(shè)備的聊天頁(yè)面會(huì)收到該聊天消息。

4.點(diǎn)擊頂部標(biāo)題欄右側(cè)的退出圖標(biāo)按鈕,則返回已登錄的用戶頁(yè)面。

5.點(diǎn)擊聊天頁(yè)面中的昵稱欄,會(huì)彈出一個(gè)菜單,選擇離線選項(xiàng)后,兩端設(shè)備的狀態(tài)圖標(biāo)都會(huì)切換為離線圖標(biāo),并且昵稱欄都會(huì)變成灰色,此時(shí)任何一端發(fā)送消息另一端都接收不到消息。

6.當(dāng)點(diǎn)擊昵稱欄再次切換為在線狀態(tài),則兩端的己方賬號(hào)狀態(tài)會(huì)切換為在線圖標(biāo),同時(shí)兩端的昵稱欄會(huì)顯示藍(lán)色,此時(shí)可正常收發(fā)消息。

工程目錄

entry/src/main/ets/MainAbility
|---app.ets
|---model
|   |---chatBox.ts                     // 聊天頁(yè)面
|   |---DataSource.ts                  // 數(shù)據(jù)獲取
|   |---Logger.ts                      // 日志工具
|---pages
|   |---Index.ets                      // 監(jiān)聽(tīng)消息頁(yè)面
|   |---Login.ets                      // 首頁(yè)登錄頁(yè)面
|---Utils
|   |---Utils.ets

具體實(shí)現(xiàn)

  • 本示例分為三個(gè)模塊
    • 輸入對(duì)端IP模塊
      • 使用wifi.getIpInfo()方法獲取IP地址,constructUDPSocketInstance方法創(chuàng)建一個(gè)UDPSocket對(duì)象
      • 源碼鏈接:[Login.ets]
/*
 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import wifi from '@ohos.wifi';
import router from '@ohos.router';
import { resolveIP } from '../Utils/Util'
import socket from '@ohos.net.socket';
import Logger from '../model/Logger'

const TAG: string = '[Login]'

let localAddr = {
  address: resolveIP(wifi.getIpInfo().ipAddress),
  family: 1,
  port: 0
}
let oppositeAddr = {
  address: '',
  family: 1,
  port: 0
}
let loginCount = 0

let udp = socket.constructUDPSocketInstance()

@Entry
@Component
struct Login {
  @State login_feng: boolean = false
  @State login_wen: boolean = false
  @State user: string = ''
  @State roomDialog: boolean = false
  @State confirmDialog: boolean = false
  @State ipDialog: boolean = true
  @State warnDialog: boolean = false
  @State warnText: string = ''
  @State roomNumber: string = ''
  @State receiveMsg: string = ''

  bindOption() {
    let bindOption = udp.bind(localAddr);
    bindOption.then(() = > {
      Logger.info(TAG, 'bind success');
    }).catch(err = > {
      Logger.info(TAG, 'bind fail');
    })
    udp.on('message', data = > {
      Logger.info(TAG, `data:${JSON.stringify(data)}`);
      let buffer = data.message;
      let dataView = new DataView(buffer);
      Logger.info(TAG, `length = ${dataView.byteLength}`);
      let str = '';
      for (let i = 0;i < dataView.byteLength; ++i) {
        let c = String.fromCharCode(dataView.getUint8(i));
        if (c != '') {
          str += c;
        }
      }
      if (str == 'ok') {
        router.clear();
        loginCount += 1;
        router.push({
          url: 'pages/Index',
          params: { address: oppositeAddr.address, port: oppositeAddr.port, loginCount: loginCount }
        })
      }
      else {
        this.receiveMsg = str;
        this.confirmDialog = true;
      }
    })
  }

  build() {
    Stack({ alignContent: Alignment.Center }) {
      Column() {
        Text($r('app.string.MainAbility_label'))
          .width('100%')
          .height(50)
          .backgroundColor('#0D9FFB')
          .textAlign(TextAlign.Start)
          .fontSize(25)
          .padding({ left: 10 })
          .fontColor(Color.White)
          .fontWeight(FontWeight.Bold)
        if (!this.ipDialog) {
          Column() {
            Image(this.login_feng ? $r('app.media.fengziOn') : $r('app.media.wenziOn'))
              .width(100)
              .height(100)
              .objectFit(ImageFit.Fill)
            Text('用戶名:' + this.user).fontSize(25).margin({ top: 50 })

            Button() {
              Text($r('app.string.create_room')).fontSize(25).fontColor(Color.White)
            }
            .width('150')
            .height(50)
            .margin({ top: 30 })
            .type(ButtonType.Capsule)
            .onClick(() = > {
              this.roomDialog = true
              this.bindOption()
            })
          }.width('90%').margin({ top: 100 })
        }

      }.width('100%').height('100%')

      if (this.confirmDialog) {
        Column() {
          Text('確認(rèn)碼:' + this.receiveMsg).fontSize(25)
          Row() {
            Button($r('app.string.cancel'))
              .onClick(() = > {
                this.confirmDialog = false
              }).backgroundColor(0xffffff).fontColor(Color.Black)
            Button($r('app.string.confirm'))
              .onClick(() = > {
                udp.send({
                  data: 'ok',
                  address: oppositeAddr
                }).then(function (data) {
                  Logger.info(TAG, `send ${JSON.stringify(data)}`);
                }).catch(function (err) {
                  Logger.info(TAG, `send ${JSON.stringify(err)}`);
                })
                router.clear()
                loginCount += 1;
                router.push({
                  url: 'pages/Index',
                  params: { address: oppositeAddr.address, port: oppositeAddr.port, loginCount: loginCount }
                })
                this.confirmDialog = false;
              }).backgroundColor(0xffffff).fontColor(Color.Red)
          }.margin({ bottom: 10 })
          .justifyContent(FlexAlign.SpaceAround)
        }
        .width('80%')
        .height(150)
        .margin({ top: '10%' })
        .backgroundColor(Color.White)
        .border({ radius: 10, width: 3 })
      }
      if (this.ipDialog) {
        Column() {
          Text('本地IP:' + localAddr.address).fontSize(25).margin({ top: 10 })
          Text('用戶:' + this.user).fontSize(20).margin({ top: 10 })
            .bindMenu([{
              value: '風(fēng)子',
              action: () = > {
                this.user = '風(fēng)子'
                this.login_feng = true
                this.login_wen = false
                localAddr.port = 8080
                oppositeAddr.port = 9090
              }
            },
              {
                value: '蚊子',
                action: () = > {
                  this.user = '蚊子'
                  this.login_wen = true
                  this.login_feng = false
                  localAddr.port = 9090
                  oppositeAddr.port = 8080
                }
              }
            ])
          TextInput({ placeholder: '請(qǐng)輸入對(duì)端ip' })
            .width(200)
            .fontSize(25)
            .margin({ top: 10 })
            .onChange((value: string) = > {
              oppositeAddr.address = value;
            })

          if (this.warnDialog) {
            Text(this.warnText).fontSize(10).fontColor(Color.Red).margin({ top: 5 })
          }
          Button($r('app.string.confirm'))
            .fontColor(Color.Black)
            .height(30)
            .margin({ bottom: 10 })
            .onClick(() = > {
              if (this.user == '') {
                this.warnDialog = true;
                this.warnText = '請(qǐng)先選擇用戶';
              } else if (oppositeAddr.address === '') {
                this.warnDialog = true;
                this.warnText = '請(qǐng)先輸入對(duì)端IP';
              } else {
                this.bindOption()
                this.ipDialog = false;
                Logger.debug(TAG, `peer ip=${oppositeAddr.address}`);
                Logger.debug(TAG, `peer port=${oppositeAddr.port}`);
                Logger.debug(TAG, `peer port=${localAddr.port}`);
              }
            })
            .backgroundColor(0xffffff)
        }
        .width('80%')
        .height(200)
        .margin({ top: '10%' })
        .backgroundColor(Color.White)
        .border({ radius: 10, width: 3 })
      }
      if (this.roomDialog) {
        Column() {
          Text($r('app.string.input_roomNumber')).fontSize(25).margin({ top: 10 })
          TextInput()
            .width(100)
            .fontSize(25)
            .margin({ top: 10 })
            .onChange((value: string) = > {
              this.roomNumber = value;
            })
          Row() {
            Button($r('app.string.cancel'))
              .onClick(() = > {
                this.roomDialog = false
              }).backgroundColor(0xffffff).fontColor(Color.Black)
            Button($r('app.string.confirm'))
              .onClick(() = > {
                Logger.info(TAG, `[ROOM]address=${oppositeAddr.address}`);
                Logger.info(TAG, `[ROOM]port=${oppositeAddr.port}`);
                /*點(diǎn)擊確定后發(fā)送房間號(hào),另一端開(kāi)始監(jiān)聽(tīng)*/
                Logger.info(TAG, `[ROOM]oppositeAddr.address=${oppositeAddr.address}`);
                Logger.info(TAG, `[ROOM]oppositeAddr.port=${oppositeAddr.port}`);
                Logger.info(TAG, `[ROOM]localAddr.address=${localAddr.address}`);
                Logger.info(TAG, `[ROOM]localAddr.port=${localAddr.port}`);
                this.bindOption()
                udp.send({
                  data: this.roomNumber,
                  address: oppositeAddr
                }).then(function (data) {
                  Logger.info(TAG, `send success, data = ${JSON.stringify(data)}`);
                }).catch(function (err) {
                  Logger.info(TAG, `send fail, err = ${JSON.stringify(err)}`);
                })
                this.roomDialog = false;
              }).backgroundColor(0xffffff).fontColor(Color.Red)
          }.margin({ bottom: 10 })
          .justifyContent(FlexAlign.SpaceAround)
        }
        .width('80%')
        .height(150)
        .margin({ top: '10%' })
        .backgroundColor(Color.White)
        .border({ radius: 10, width: 3 })
      }
    }
  }
}

[Util.ets]

/*

* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
  */

export function resolveIP(ip) {
if (ip < 0 || ip > 0xFFFFFFFF) {
throw ('The number is not normal!');
}
return (ip > >> 24) + '.' + (ip > > 16 & 0xFF) + '.' + (ip > > 8 & 0xFF) + '.' + (ip & 0xFF);
}
  • 創(chuàng)建房間模塊
    • 點(diǎn)擊創(chuàng)建房間按鈕,彈出創(chuàng)建房間框,輸入房間號(hào),點(diǎn)擊確定,進(jìn)入聊天頁(yè)面
    • 源碼鏈接:[Login.ets]
/*
 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import wifi from '@ohos.wifi';
import router from '@ohos.router';
import { resolveIP } from '../Utils/Util'
import socket from '@ohos.net.socket';
import Logger from '../model/Logger'

const TAG: string = '[Login]'

let localAddr = {
  address: resolveIP(wifi.getIpInfo().ipAddress),
  family: 1,
  port: 0
}
let oppositeAddr = {
  address: '',
  family: 1,
  port: 0
}
let loginCount = 0

let udp = socket.constructUDPSocketInstance()

@Entry
@Component
struct Login {
  @State login_feng: boolean = false
  @State login_wen: boolean = false
  @State user: string = ''
  @State roomDialog: boolean = false
  @State confirmDialog: boolean = false
  @State ipDialog: boolean = true
  @State warnDialog: boolean = false
  @State warnText: string = ''
  @State roomNumber: string = ''
  @State receiveMsg: string = ''

  bindOption() {
    let bindOption = udp.bind(localAddr);
    bindOption.then(() = > {
      Logger.info(TAG, 'bind success');
    }).catch(err = > {
      Logger.info(TAG, 'bind fail');
    })
    udp.on('message', data = > {
      Logger.info(TAG, `data:${JSON.stringify(data)}`);
      let buffer = data.message;
      let dataView = new DataView(buffer);
      Logger.info(TAG, `length = ${dataView.byteLength}`);
      let str = '';
      for (let i = 0;i < dataView.byteLength; ++i) {
        let c = String.fromCharCode(dataView.getUint8(i));
        if (c != '') {
          str += c;
        }
      }
      if (str == 'ok') {
        router.clear();
        loginCount += 1;
        router.push({
          url: 'pages/Index',
          params: { address: oppositeAddr.address, port: oppositeAddr.port, loginCount: loginCount }
        })
      }
      else {
        this.receiveMsg = str;
        this.confirmDialog = true;
      }
    })
  }

  build() {
    Stack({ alignContent: Alignment.Center }) {
      Column() {
        Text($r('app.string.MainAbility_label'))
          .width('100%')
          .height(50)
          .backgroundColor('#0D9FFB')
          .textAlign(TextAlign.Start)
          .fontSize(25)
          .padding({ left: 10 })
          .fontColor(Color.White)
          .fontWeight(FontWeight.Bold)
        if (!this.ipDialog) {
          Column() {
            Image(this.login_feng ? $r('app.media.fengziOn') : $r('app.media.wenziOn'))
              .width(100)
              .height(100)
              .objectFit(ImageFit.Fill)
            Text('用戶名:' + this.user).fontSize(25).margin({ top: 50 })

            Button() {
              Text($r('app.string.create_room')).fontSize(25).fontColor(Color.White)
            }
            .width('150')
            .height(50)
            .margin({ top: 30 })
            .type(ButtonType.Capsule)
            .onClick(() = > {
              this.roomDialog = true
              this.bindOption()
            })
          }.width('90%').margin({ top: 100 })
        }

      }.width('100%').height('100%')

      if (this.confirmDialog) {
        Column() {
          Text('確認(rèn)碼:' + this.receiveMsg).fontSize(25)
          Row() {
            Button($r('app.string.cancel'))
              .onClick(() = > {
                this.confirmDialog = false
              }).backgroundColor(0xffffff).fontColor(Color.Black)
            Button($r('app.string.confirm'))
              .onClick(() = > {
                udp.send({
                  data: 'ok',
                  address: oppositeAddr
                }).then(function (data) {
                  Logger.info(TAG, `send ${JSON.stringify(data)}`);
                }).catch(function (err) {
                  Logger.info(TAG, `send ${JSON.stringify(err)}`);
                })
                router.clear()
                loginCount += 1;
                router.push({
                  url: 'pages/Index',
                  params: { address: oppositeAddr.address, port: oppositeAddr.port, loginCount: loginCount }
                })
                this.confirmDialog = false;
              }).backgroundColor(0xffffff).fontColor(Color.Red)
          }.margin({ bottom: 10 })
          .justifyContent(FlexAlign.SpaceAround)
        }
        .width('80%')
        .height(150)
        .margin({ top: '10%' })
        .backgroundColor(Color.White)
        .border({ radius: 10, width: 3 })
      }
      if (this.ipDialog) {
        Column() {
          Text('本地IP:' + localAddr.address).fontSize(25).margin({ top: 10 })
          Text('用戶:' + this.user).fontSize(20).margin({ top: 10 })
            .bindMenu([{
              value: '風(fēng)子',
              action: () = > {
                this.user = '風(fēng)子'
                this.login_feng = true
                this.login_wen = false
                localAddr.port = 8080
                oppositeAddr.port = 9090
              }
            },
              {
                value: '蚊子',
                action: () = > {
                  this.user = '蚊子'
                  this.login_wen = true
                  this.login_feng = false
                  localAddr.port = 9090
                  oppositeAddr.port = 8080
                }
              }
            ])
          TextInput({ placeholder: '請(qǐng)輸入對(duì)端ip' })
            .width(200)
            .fontSize(25)
            .margin({ top: 10 })
            .onChange((value: string) = > {
              oppositeAddr.address = value;
            })

          if (this.warnDialog) {
            Text(this.warnText).fontSize(10).fontColor(Color.Red).margin({ top: 5 })
          }
          Button($r('app.string.confirm'))
            .fontColor(Color.Black)
            .height(30)
            .margin({ bottom: 10 })
            .onClick(() = > {
              if (this.user == '') {
                this.warnDialog = true;
                this.warnText = '請(qǐng)先選擇用戶';
              } else if (oppositeAddr.address === '') {
                this.warnDialog = true;
                this.warnText = '請(qǐng)先輸入對(duì)端IP';
              } else {
                this.bindOption()
                this.ipDialog = false;
                Logger.debug(TAG, `peer ip=${oppositeAddr.address}`);
                Logger.debug(TAG, `peer port=${oppositeAddr.port}`);
                Logger.debug(TAG, `peer port=${localAddr.port}`);
              }
            })
            .backgroundColor(0xffffff)
        }
        .width('80%')
        .height(200)
        .margin({ top: '10%' })
        .backgroundColor(Color.White)
        .border({ radius: 10, width: 3 })
      }
      if (this.roomDialog) {
        Column() {
          Text($r('app.string.input_roomNumber')).fontSize(25).margin({ top: 10 })
          TextInput()
            .width(100)
            .fontSize(25)
            .margin({ top: 10 })
            .onChange((value: string) = > {
              this.roomNumber = value;
            })
          Row() {
            Button($r('app.string.cancel'))
              .onClick(() = > {
                this.roomDialog = false
              }).backgroundColor(0xffffff).fontColor(Color.Black)
            Button($r('app.string.confirm'))
              .onClick(() = > {
                Logger.info(TAG, `[ROOM]address=${oppositeAddr.address}`);
                Logger.info(TAG, `[ROOM]port=${oppositeAddr.port}`);
                /*點(diǎn)擊確定后發(fā)送房間號(hào),另一端開(kāi)始監(jiān)聽(tīng)*/
                Logger.info(TAG, `[ROOM]oppositeAddr.address=${oppositeAddr.address}`);
                Logger.info(TAG, `[ROOM]oppositeAddr.port=${oppositeAddr.port}`);
                Logger.info(TAG, `[ROOM]localAddr.address=${localAddr.address}`);
                Logger.info(TAG, `[ROOM]localAddr.port=${localAddr.port}`);
                this.bindOption()
                udp.send({
                  data: this.roomNumber,
                  address: oppositeAddr
                }).then(function (data) {
                  Logger.info(TAG, `send success, data = ${JSON.stringify(data)}`);
                }).catch(function (err) {
                  Logger.info(TAG, `send fail, err = ${JSON.stringify(err)}`);
                })
                this.roomDialog = false;
              }).backgroundColor(0xffffff).fontColor(Color.Red)
          }.margin({ bottom: 10 })
          .justifyContent(FlexAlign.SpaceAround)
        }
        .width('80%')
        .height(150)
        .margin({ top: '10%' })
        .backgroundColor(Color.White)
        .border({ radius: 10, width: 3 })
      }
    }
  }
}

[Util.ets]

/*
 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

export function resolveIP(ip) {
  if (ip < 0 || ip > 0xFFFFFFFF) {
    throw ('The number is not normal!');
  }
  return (ip > >> 24) + '.' + (ip > > 16 & 0xFF) + '.' + (ip > > 8 & 0xFF) + '.' + (ip & 0xFF);
}

相關(guān)概念

UDP Socket是面向非連接的協(xié)議,它不與對(duì)方建立連接,而是直接把我要發(fā)的數(shù)據(jù)報(bào)發(fā)給對(duì)方,適用于一次傳輸數(shù)據(jù)量很少、對(duì)可靠性要求不高的或?qū)?shí)時(shí)性要求高的應(yīng)用場(chǎng)景。

相關(guān)權(quán)限

1.允許使用Internet網(wǎng)絡(luò)權(quán)限:[ohos.permission.INTERNET]

2.允許應(yīng)用獲取WLAN信息權(quán)限:[ohos.permission.GET_WIFI_INFO]

依賴

不涉及。

約束與限制

1.本示例僅支持標(biāo)準(zhǔn)系統(tǒng)上運(yùn)行,支持設(shè)備:RK3568。

2.本示例僅支持API9版本SDK,版本號(hào):3.2.11.9 及以上。

3.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400 構(gòu)建 2023年4月7日)及以上才可編譯運(yùn)行。

下載

如需單獨(dú)下載本工程,執(zhí)行如下命令:

git init
git config core.sparsecheckout true
echo codeBasicFeatureConnectivitySocket > .git/info/sparse-checkout
git remote add origin https://gitee.com/openharmony/applications_app_samples.git
git pull origin master

審核編輯 黃宇

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • Socket
    +關(guān)注

    關(guān)注

    1

    文章

    212

    瀏覽量

    35542
  • 網(wǎng)絡(luò)通信
    +關(guān)注

    關(guān)注

    4

    文章

    824

    瀏覽量

    30731
  • 鴻蒙
    +關(guān)注

    關(guān)注

    59

    文章

    2503

    瀏覽量

    43762
收藏 人收藏

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    HarmonyOS 網(wǎng)絡(luò)管理開(kāi)發(fā)Socket 連接

    簡(jiǎn)介 Socket 連接主要是通過(guò) Socket 進(jìn)行數(shù)據(jù)傳輸,支持 TCP/UDP/TLS 協(xié)議。 基本概念 ? ● Socket:套接字,就是對(duì)
    的頭像 發(fā)表于 02-18 09:20 ?1192次閱讀

    鴻蒙實(shí)戰(zhàn)項(xiàng)目開(kāi)發(fā):【短信服務(wù)】

    環(huán)境搭建 ? 《鴻蒙開(kāi)發(fā)基礎(chǔ)》 ArkTS語(yǔ)言 安裝DevEco Studio 運(yùn)用你的第一個(gè)ArkTS應(yīng)用 ArkUI聲明式UI開(kāi)發(fā) .…… ? 《鴻蒙
    發(fā)表于 03-03 21:29

    鴻蒙原生應(yīng)用開(kāi)發(fā)-網(wǎng)絡(luò)管理Socket連接(一)

    一、簡(jiǎn)介 Socket連接主要是通過(guò)Socket進(jìn)行數(shù)據(jù)傳輸,支持TCP/UDP/TLS協(xié)議。 二、基本概念 Socket:套接字,就是對(duì)網(wǎng)絡(luò)
    發(fā)表于 04-01 14:20

    鴻蒙原生應(yīng)用開(kāi)發(fā)-網(wǎng)絡(luò)管理Socket連接(二)

    應(yīng)用TCP/UDP協(xié)議進(jìn)行通信 1.UDP與TCP流程大體類似,下面以TCP為例: 2.import需要的socket模塊。 3.創(chuàng)建一個(gè)TCPSocket連接,返回一個(gè)TCPSocket對(duì)象
    發(fā)表于 04-02 15:22

    鴻蒙原生應(yīng)用開(kāi)發(fā)-網(wǎng)絡(luò)管理Socket連接(三)

    應(yīng)用通過(guò)TLS Socket進(jìn)行加密數(shù)據(jù)傳輸 開(kāi)發(fā)步驟 客戶端TLS Socket流程: 1.import需要的socket模塊。 2.綁定服務(wù)器IP和端口號(hào)。 3.雙向認(rèn)證上傳客戶端
    發(fā)表于 04-03 14:26

    鴻蒙原生應(yīng)用開(kāi)發(fā)-網(wǎng)絡(luò)管理模塊總述

    一、網(wǎng)絡(luò)管理模塊主要提供以下功能: HTTP數(shù)據(jù)請(qǐng)求:通過(guò)HTTP發(fā)起一個(gè)數(shù)據(jù)請(qǐng)求。 WebSocket連接:使用WebSocket建立服務(wù)器與客戶端的雙向連接
    發(fā)表于 04-08 09:45

    鴻蒙Flutter實(shí)戰(zhàn):07混合開(kāi)發(fā)

    # 鴻蒙Flutter實(shí)戰(zhàn):混合開(kāi)發(fā) 鴻蒙Flutter混合開(kāi)發(fā)主要有兩種形式。 ## 1.基于har 將flutter module
    發(fā)表于 10-23 16:00

    實(shí)戰(zhàn)Linux Socket編程

    實(shí)戰(zhàn)Linux Socket編程
    發(fā)表于 03-03 10:17

    【中秋國(guó)慶不斷更】HarmonyOS網(wǎng)絡(luò)管理開(kāi)發(fā)Socket連接

    簡(jiǎn)介 Socket連接主要是通過(guò)Socket進(jìn)行數(shù)據(jù)傳輸,支持TCP/UDP/TLS協(xié)議。 基本概念 ● Socket:套接字,就是對(duì)網(wǎng)絡(luò)
    發(fā)表于 09-27 15:44

    什么是Socket連接Socket與TCP連接的關(guān)系

    主機(jī) A 的應(yīng)用程序必須通過(guò) Socket 建立連接才能與主機(jī)B的應(yīng)用程序通信,而建立 Socket 連接需要底層 TCP/IP 協(xié)議來(lái)建立 TCP
    發(fā)表于 03-31 15:10 ?1274次閱讀

    Socket 網(wǎng)絡(luò)編程框架介紹

    Socket 網(wǎng)絡(luò)編程框架 Socket(套接字)是一個(gè)網(wǎng)絡(luò)編程概念,描述了一個(gè)通信端點(diǎn)(Endpoint),用于建立網(wǎng)絡(luò)連接(Connec
    的頭像 發(fā)表于 11-09 14:19 ?1398次閱讀
    <b class='flag-5'>Socket</b> <b class='flag-5'>網(wǎng)絡(luò)</b>編程框架介紹

    什么是Socket連接Socket的工作原理 它與TCP連接有什么關(guān)系?

    和服務(wù)器之間的數(shù)據(jù)交換。 Socket連接的工作原理是基于TCP/IP協(xié)議。TCP(傳輸控制協(xié)議)是一種面向連接的、可靠的傳輸協(xié)議,用于在網(wǎng)絡(luò)中的兩個(gè)應(yīng)用程序之間建立可靠的通信。而
    的頭像 發(fā)表于 01-22 16:10 ?3034次閱讀

    鴻蒙OS開(kāi)發(fā)實(shí)戰(zhàn):【Socket小試MQTT連接

    本篇分享一下 HarmonyOS 中的Socket使用方法 將從2個(gè)方面實(shí)踐: 1. HarmonyOS 手機(jī)應(yīng)用連接PC端 SocketServer 1. HarmonyOS 手機(jī)應(yīng)用連接MQTT 服務(wù)端
    的頭像 發(fā)表于 04-01 16:14 ?1946次閱讀
    <b class='flag-5'>鴻蒙</b>OS<b class='flag-5'>開(kāi)發(fā)</b><b class='flag-5'>實(shí)戰(zhàn)</b>:【<b class='flag-5'>Socket</b>小試MQTT<b class='flag-5'>連接</b>】

    socket連接超時(shí)如何處理

    網(wǎng)絡(luò)編程中,socket連接超時(shí)是一個(gè)常見(jiàn)的問(wèn)題,它可能由多種原因引起,比如網(wǎng)絡(luò)延遲、服務(wù)器負(fù)載過(guò)高或者客戶端請(qǐng)求超時(shí)設(shè)置過(guò)短等。處理socket
    的頭像 發(fā)表于 11-01 16:48 ?2031次閱讀

    socket 連接超時(shí)處理技巧

    網(wǎng)絡(luò)編程中,Socket連接超時(shí)是一個(gè)常見(jiàn)的問(wèn)題。處理超時(shí)的關(guān)鍵在于確保程序能夠優(yōu)雅地處理這些情況,避免程序崩潰或者無(wú)響應(yīng)。以下是一些處理Socket
    的頭像 發(fā)表于 11-12 14:13 ?1063次閱讀