Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.46 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  BotDofus
  4. //
  5. //  Created by Christopher Yovanovitch on 25/04/2017.
  6. //  Copyright © 2017 Christopher Yovanovitch. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController {
  12.    
  13.     let host = "213.248.126.39"
  14.     let port = 5555
  15.     var client: TCPClient?
  16.  
  17.     override func viewDidLoad() {
  18.         super.viewDidLoad()
  19.        
  20.         client = TCPClient(address: host, port: Int32(port))
  21.        
  22.         guard let client = client else { return }
  23.        
  24.         switch client.connect(timeout: 10) {
  25.         case .success:
  26.             print("🎉 Connected! 🎉")
  27.            
  28.             if let data = client.read(1024 * 10) {
  29.                 print(data.debugDescription)
  30.             } else {
  31.                 print("error..")
  32.             }
  33.            
  34. //            switch client.send(data: [1, 2, 3]) {
  35. //            case .success:
  36. //                print("Successfully send data..")
  37. //                guard let data = client.read(1024 * 10) else { return }
  38. //                
  39. //                if let response = String(bytes: data, encoding: .utf8) {
  40. //                    print(response)
  41. //                }
  42. //            case .failure(let error):
  43. //                print("💩: \(error.localizedDescription)")
  44. //            }
  45.            
  46.             break
  47.         case .failure(let error):
  48.             print("💩: \(error.localizedDescription)")
  49.             break
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement