Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ソケットについて

jambo-develop-team
March 11, 2024
28

 ソケットについて

TCP/IP等ネットワークプロトコルを使って データを双方向で送受信するための手段
TCP/IPという技術を使いやすくした API、ライブラリのようなもの

jambo-develop-team

March 11, 2024
Tweet

Transcript

  1. αʔόʔ ΫϥΠΞϯτ 4PDLFU 4PDLFU MJTUFO DPOOFDU SFDFJWF TFOE SFDFJWF TFOE

    DMPTF DMPTF ίωΫγϣϯ४උ ίωΫγϣϯཱ֬ σʔλަ׵ ίωΫγϣϯղ๏
  2. ιέοτΫϥΠΞϯτଆ final class SocketClient { init(_ loginUser: LoginUserEntity) { self.loginUser

    = loginUser let host = NWEndpoint.Host(CustomUrl.targetIp) let port = NWEndpoint.Port(integerLiteral: CustomUrl.Port) let using: NWParameters = .tcp connection = NWConnection(host: host, port: port, using: using) connection.stateUpdateHandler = {[weak self] newState in guard let strongSelf = self else { return } strongSelf.connectionState = newState switch newState { case .setup: print("HOGE: ηοτΞοϓ”) case .waiting: print("HOGE: ଴ػ") case .preparing: print("HOGE: ४උ") case .ready: print("HOGE: ४උ׬ྃ”) private static let productionIp = “xxx.com” static let port: UInt16 = 8_888 J04ΞϓϦ ιέοτॳظԽॲཧ ίωΫγϣϯͷ४උ ίωΫγϣϯཱ֬
  3. ιέοτΫϥΠΞϯτଆ final class SocketClient { init(_ loginUser: LoginUserEntity) { self.loginUser

    = loginUser let host = NWEndpoint.Host(CustomUrl.targetIp) let port = NWEndpoint.Port(integerLiteral: ɹɹɹɹɹɹɹɹɹɹɹCustomUrl.port) let using: NWParameters = .tcp connection = NWConnection(host: host, port: port, using: using) connection.stateUpdateHandler = {[weak self] newState in guard let strongSelf = self else { return } strongSelf.connectionState = newState switch newState { case .setup: print("HOGE: ηοτΞοϓ”) case .waiting: print("HOGE: ଴ػ") case .preparing: print("HOGE: ४උ") case .ready: print("HOGE: ४උ׬ྃ”) private static let productionIp = “xxx.com” static let port: UInt16 = 8_888 Πϯλʔωοτ૚ τϥϯεϙʔτ૚ τϥϯεϙʔτ૚ ʁʁʁ
  4. ιέοτΫϥΠΞϯτଆ final class SocketClient { init(_ loginUser: LoginUserEntity) { self.loginUser

    = loginUser let host = NWEndpoint.Host(CustomUrl.targetIp) let port = NWEndpoint.Port(integerLiteral: ɹɹɹɹɹɹɹɹɹɹɹCustomUrl.port) let using: NWParameters = .tcp connection = NWConnection(host: host, port: port, using: using) connection.stateUpdateHandler = {[weak self] newState in guard let strongSelf = self else { return } strongSelf.connectionState = newState switch newState { case .setup: print("HOGE: ηοτΞοϓ”) case .waiting: print("HOGE: ଴ػ") case .preparing: print("HOGE: ४උ") case .ready: print("HOGE: ४උ׬ྃ”) private static let productionIp = “xxx.com” static let port: UInt16 = 8_888 Πϯλʔωοτ૚ τϥϯεϙʔτ૚ τϥϯεϙʔτ૚ ΢ΣΠϋϯυγΣΠΫ
  5. ιέοτΫϥΠΞϯτଆ func send(to receiver: SocketMsgProtocol, text: String, messageType: ChatMessageType, handler:

    @escaping (SocketMessage?) -> Void) { ~~~~ } func receive(on connection: NWConnection) { connection.receive(minimumIncompleteLength: 0, maximumLength: Int(UInt32.max)) {[weak self] (data, _, _, error) in guard let text = data?.toStringWithEncodeByUTF8() ~~~ } σʔλަ׵