xcode demo app UI updates

This commit is contained in:
Joseph Henry
2016-07-18 15:52:02 -07:00
parent e301b9c654
commit 58c2ed2299
6 changed files with 161 additions and 102 deletions

View File

@@ -10,27 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example_OSX_App/ViewController.swift"
timestampString = "489623400.349295"
timestampString = "490574990.533534"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "78"
endingLineNumber = "78"
landmarkName = "UI_Connect(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example_OSX_App/ViewController.swift"
timestampString = "489623400.349295"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "155"
endingLineNumber = "155"
startingLineNumber = "174"
endingLineNumber = "174"
landmarkName = "UI_SendData(_:)"
landmarkType = "5">
</BreakpointContent>
@@ -42,43 +26,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example_OSX_App/ViewController.swift"
timestampString = "489623686.632265"
timestampString = "490574990.533534"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "137"
endingLineNumber = "137"
landmarkName = "UI_Bind(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example_OSX_App/ViewController.swift"
timestampString = "489623690.124704"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "139"
endingLineNumber = "139"
landmarkName = "UI_Bind(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example_OSX_App/ViewController.swift"
timestampString = "490569637.32756"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "179"
endingLineNumber = "179"
startingLineNumber = "194"
endingLineNumber = "194"
landmarkName = "UI_ReadData(_:)"
landmarkType = "5">
</BreakpointContent>
@@ -94,9 +46,7 @@
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "50"
endingLineNumber = "50"
landmarkName = "zts_socket(SOCKET_SIG)"
landmarkType = "7">
endingLineNumber = "50">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@@ -106,11 +56,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Example_OSX_App/ViewController.swift"
timestampString = "490569637.32756"
timestampString = "490574990.533534"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "178"
endingLineNumber = "178"
startingLineNumber = "193"
endingLineNumber = "193"
landmarkName = "UI_ReadData(_:)"
landmarkType = "5">
</BreakpointContent>

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<capability name="box content view" minToolsVersion="7.0"/>
</dependencies>
<scenes>

View File

@@ -71,9 +71,10 @@ class ViewController: NSViewController {
}
}
// Connect to remote host on ZeroTier virtual network
@IBAction func UI_Connect(sender: AnyObject) {
// CONNECT
var connect_thread : NSThread!
func attempt_connect()
{
// TCP
if(selectedProtocol == SOCK_STREAM)
{
@@ -103,8 +104,18 @@ class ViewController: NSViewController {
}
}
// Bind a ZeroTier socket
@IBAction func UI_Bind(sender: AnyObject) {
// Connect to remote host on ZeroTier virtual network
@IBAction func UI_Connect(sender: AnyObject) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
self.connect_thread = NSThread(target:self, selector:"attempt_connect", object:nil)
self.connect_thread.start()
});
}
// BIND
var bind_thread : NSThread!
func attempt_bind()
{
// TCP
if(selectedProtocol == SOCK_STREAM)
{
@@ -146,6 +157,14 @@ class ViewController: NSViewController {
}
}
// Bind a ZeroTier socket
@IBAction func UI_Bind(sender: AnyObject) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
self.bind_thread = NSThread(target:self, selector:"attempt_bind", object:nil)
self.bind_thread.start()
});
}
// TX
@IBOutlet weak var btnSend: NSButton!
@IBAction func UI_SendData(sender: AnyObject) {
@@ -170,10 +189,6 @@ class ViewController: NSViewController {
if(selectedProtocol == SOCK_STREAM)
{
var buffer = [UInt8](count: 100, repeatedValue: 0)
let str = "GET / HTTP/1.0\r\n\r\n"
//let str = "Welcome to the machine"
print("strlen = %d\n", str.characters.count)
let encodedDataArray = [UInt8](str.utf8)
read(accepted_sock, &buffer, 1024);
print(buffer)
@@ -185,6 +200,39 @@ class ViewController: NSViewController {
}
}
// Watch for incoming data
var rx_thread : NSThread!
func update_rx() {
while(true)
{
sleep(1)
// TCP
if(selectedProtocol == SOCK_STREAM)
{
var len = 32
var buffer = [UInt8](count: len, repeatedValue: 0)
let n = read(accepted_sock, &buffer, len);
if(n > 0)
{
if let str = String(data: NSData(bytes: &buffer, length: len), encoding: NSUTF8StringEncoding) {
dispatch_async(dispatch_get_main_queue()) {
self.txtRX.stringValue = str
}
} else {
print("not a valid UTF-8 sequence")
}
}
}
// UDP
if(selectedProtocol == SOCK_DGRAM)
{
// recvfrom
}
}
}
// Built-in SOCKS5 Proxy Server Test
func test_client_proxy_nsstream()
{
// For HTTP request
@@ -216,16 +264,15 @@ class ViewController: NSViewController {
outputStream?.write(encodedDataArray, maxLength: encodedDataArray.count)
// RX
//sleep(5)
//inputStream?.read(&buffer, maxLength: 100)
//print("buffer = \(buffer)\n")
sleep(5)
inputStream?.read(&buffer, maxLength: 100)
print("buffer = \(buffer)\n")
}
var service_thread : NSThread!
func ztnc_start_service() {
// If you plan on using SOCKS Proxy, you don't need to initialize the RPC
//start_service("/Users/Joseph/utest3")
// If you plan on using direct calls via RPC
start_service_and_rpc("/Users/Joseph/utest3","565799d8f65063e5");
}
@@ -244,6 +291,12 @@ class ViewController: NSViewController {
self.service_thread = NSThread(target:self, selector:"ztnc_start_service", object:nil)
self.service_thread.start()
});
// Update UI on RX of data
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
self.rx_thread = NSThread(target:self, selector:"update_rx", object:nil)
self.rx_thread.start()
});
}
override var representedObject: AnyObject? {

View File

@@ -32,8 +32,7 @@
<rect key="frame" x="183" y="352" width="31" height="30"/>
<state key="normal" title="Bind"/>
<connections>
<action selector="UI_Bind:" destination="BYZ-38-t0r" eventType="touchUpInside" id="03t-PZ-jaE"/>
<action selector="btnBind:" destination="BYZ-38-t0r" eventType="touchUpInside" id="L5k-Rt-Lwm"/>
<action selector="UI_Bind:" destination="BYZ-38-t0r" eventType="touchUpInside" id="DJq-47-7gO"/>
</connections>
</button>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="ip address" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="6id-4C-E8W">

View File

@@ -18,12 +18,11 @@ class ViewController: UIViewController {
@IBOutlet weak var txtAddr: UITextField!
@IBOutlet weak var txtPort: UITextField!
@IBOutlet weak var txtTX: UITextField!
@IBOutlet weak var txtRX: UITextField!
@IBOutlet weak var btnTX: UIButton!
@IBOutlet weak var btnConnect: UIButton!
@IBOutlet weak var btnBind: UIButton!
@IBOutlet weak var btnRX: UIButton!
@IBAction func UI_RX(sender: AnyObject) {
@@ -33,12 +32,6 @@ class ViewController: UIViewController {
if(selectedProtocol == SOCK_STREAM)
{
var buffer = [UInt8](count: 100, repeatedValue: 0)
let str = "GET / HTTP/1.0\r\n\r\n"
//let str = "Welcome to the machine"
print("strlen = %d\n", str.characters.count)
let encodedDataArray = [UInt8](str.utf8)
// read(accepted_sock, UnsafeMutablePointer<Void>([txtTX.stringValue]), 128);
read(accepted_sock, &buffer, 100);
print(buffer)
@@ -51,7 +44,6 @@ class ViewController: UIViewController {
}
@IBAction func UI_TX(sender: AnyObject) {
// Use ordinary read/write calls on ZeroTier socket
@@ -94,8 +86,11 @@ class ViewController: UIViewController {
}
}
@IBOutlet weak var btnConnect: UIButton!
@IBAction func UI_Connect(sender: AnyObject) {
// CONNECT
var connect_thread : NSThread!
func attempt_connect()
{
// TCP
if(selectedProtocol == SOCK_STREAM)
{
@@ -125,9 +120,18 @@ class ViewController: UIViewController {
}
}
// Connect to remote host on ZeroTier virtual network
@IBAction func UI_Connect(sender: AnyObject) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
self.connect_thread = NSThread(target:self, selector:"attempt_connect", object:nil)
self.connect_thread.start()
});
}
@IBOutlet weak var btnBind: UIButton!
@IBAction func UI_Bind(sender: AnyObject) {
// BIND
var bind_thread : NSThread!
func attempt_bind()
{
// TCP
if(selectedProtocol == SOCK_STREAM)
{
@@ -161,8 +165,52 @@ class ViewController: UIViewController {
}
print("accepted connection")
}
// UDP
if(selectedProtocol == SOCK_DGRAM)
{
}
}
// Bind a ZeroTier socket
@IBAction func UI_Bind(sender: AnyObject) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
self.bind_thread = NSThread(target:self, selector:"attempt_bind", object:nil)
self.bind_thread.start()
});
}
// Watch for incoming data
var rx_thread : NSThread!
func update_rx() {
while(true)
{
sleep(1)
// TCP
if(selectedProtocol == SOCK_STREAM)
{
var len = 32
var buffer = [UInt8](count: len, repeatedValue: 0)
let n = read(accepted_sock, &buffer, len);
if(n > 0)
{
if let str = String(data: NSData(bytes: &buffer, length: len), encoding: NSUTF8StringEncoding) {
dispatch_async(dispatch_get_main_queue()) {
self.txtRX.text = str
}
} else {
print("not a valid UTF-8 sequence")
}
}
}
// UDP
if(selectedProtocol == SOCK_DGRAM)
{
// recvfrom
}
}
}
// ZeroTier service thread
var service_thread : NSThread!
@@ -176,8 +224,11 @@ class ViewController: UIViewController {
txtNWID.text = "565799d8f65063e5"
txtTX.text = "welcome to the machine"
txtAddr.text = "10.9.9.203"
txtAddr.text = "0.0.0.0"
serverAddr = "0.0.0.0"
txtPort.text = "8080"
serverPort = 8080
selectedProtocol = SOCK_STREAM
// ZeroTier Service thread
@@ -186,6 +237,12 @@ class ViewController: UIViewController {
self.service_thread.start()
});
// UI RX update
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
self.rx_thread = NSThread(target:self, selector:"update_rx", object:nil)
self.rx_thread.start()
});
// Do any additional setup after loading the view, typically from a nib.
}

View File

@@ -98,20 +98,20 @@ void dwr(int level, const char *fmt, ... )
#elif defined(__APPLE__)
pid_t tid = pthread_mach_thread_np(pthread_self());
#endif
//#if defined(SDK_DEBUG_LOG_TO_FILE)
//if(!debug_logfile) { // Try to get logfile from env
// debug_logfile = getenv("ZT_SDK_LOGFILE");
//}
#if defined(SDK_DEBUG_LOG_TO_FILE)
if(!debug_logfile) { // Try to get logfile from env
debug_logfile = getenv("ZT_SDK_LOGFILE");
}
//if(debug_logfile) {
FILE *file = fopen("/Users/Joseph/code/unity.log","a");
if(debug_logfile) {
FILE *file = fopen(debug_logfile,"a");
fprintf(file, "%s [tid=%7d] ", timestring, tid);
vfprintf(file, fmt, ap);
fclose(file);
va_end(ap);
//}
}
//#endif
#endif
va_start(ap, fmt);
fprintf(stderr, "%s [tid=%7d] ", timestring, tid);
vfprintf(stderr, fmt, ap);