<commit_before>//
//  ViewController.swift
//  Swocket
//
//  Created by <NAME> on 06/19/2015.
//  Copyright (c) 06/19/2015 <NAME>. All rights reserved.
//

import UIKit
import Swocket

class ViewController: UIViewController {
    @IBOutlet weak var responseLabel: UILabel!
    @IBOutlet weak var messageField: UITextField!
    var server: Listenable?
    
    // Set up a socket to localhost on port 9999
    let client = Swocket.TCP.init(host: "127.0.0.1", port: 9999)
    
    @IBAction func send(sender: UIButton) {
        // Get text to send and convert to NSData
        if let data = messageField.text?.dataUsingEncoding(NSUTF8StringEncoding) {
            // Connect to server
            try! client.connect()

            // Send message
            try! client.sendData(data)
            
            // Get response
            client.recieveDataAsync({ (data, error) -> Void in
                // Unwrap response as string and set response label
                let response = NSString(data: data!, encoding: NSUTF8StringEncoding) as? String
                self.responseLabel.text = response
                print(response)
                try! self.client.disconnect()
            })
        }
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        let httpString = "HTTP/1.1 200 OK\nContent-Type: text/html; charset=UTF-8"
        let htmlString = "<html><head><title>Rosanna</title></head><body><h1>Hej Rosanna</h1><p>Det här serverades av min nätverkskod till browsern du kollar på det här i</p></body></html>"
        let data = "\(httpString)\n\n\(htmlString)".dataUsingEncoding(NSUTF8StringEncoding)!
        
        server = try! Swocket.TCP.listen(8080, onConnection: { (client) -> () in
            try! client.recieveData()
            try! client.sendData(data)
        })
    }
}<commit_msg>Updated example code<commit_after>//
//  ViewController.swift
//  Swocket
//
//  Created by <NAME> on 06/19/2015.
//  Copyright (c) 06/19/2015 <NAME>. All rights reserved.
//

import UIKit
import Swocket

class ViewController: UIViewController {
    @IBOutlet weak var responseLabel: UILabel!
    @IBOutlet weak var messageField: UITextField!
    var server: Listenable?
    
    // Set up a socket to localhost on port 9999
    let client = Swocket.TCP.init(host: "127.0.0.1", port: 9999)
    
    @IBAction func send(sender: UIButton) {
        // Get text to send and convert to NSData
        if let data = messageField.text?.dataUsingEncoding(NSUTF8StringEncoding) {
            // Connect to server
            try! client.connect()

            // Send message
            try! client.sendData(data)
            
            // Get response
            client.recieveDataAsync({ (data, error) -> Void in
                // Unwrap response as string and set response label
                let response = NSString(data: data!, encoding: NSUTF8StringEncoding) as? String
                self.responseLabel.text = response
                try! self.client.disconnect()
            })
        }
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        let httpString = "HTTP/1.1 200 OK\nContent-Type: text/html; charset=UTF-8"
        let htmlString = "<html><head><title>Hello</title></head><body><h1>Hello World!</h1><p>I am a tiny little web server</p></body></html>"
        let data = "\(httpString)\n\n\(htmlString)".dataUsingEncoding(NSUTF8StringEncoding)!
        
        server = try! Swocket.TCP.listen(8080, onConnection: { (client) -> () in
            try! client.recieveData() // Ignore what client requests
            try! client.sendData(data) // And give them the same result every time! :P
        })
    }
    
    override func viewDidDisappear(animated: Bool) {
        try! server?.stop()
        
        viewDidDisappear(animated)
    }
}
{'fraction_non_alphanumeric': 0.11188271604938271, 'fraction_numerical': 0.023148148148148147, 'mean_word_length': 2.1721044045677, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5307270', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1114, 'n_words': 304}