导航:首页 > IDC知识 > swiftsocket解析域名

swiftsocket解析域名

发布时间:2021-03-16 23:32:37

1、swift socket编程怎么弄

swift代码:需要导入GCDAsyncSocket库文件,可去github下载

import UIKit

class ViewController:
UIViewController,
GCDAsyncSocketDelegate {

@IBOutlet var serveripInput:
UITextField!

@IBOutlet var msgInput:
UITextField!

@IBOutlet var conBtn:
UIButton!

@IBOutlet var sendBtn:
UIButton!

@IBOutlet var msgView:
UITextView!

let serverPort: UInt16 =
9050

var clientSocket:
GCDAsyncSocket!

var mainQueue =
dispatch_get_main_queue()

override func viewDidLoad() {

super.viewDidLoad()

}

//连接服务器按钮事件

@IBAction func conBtnClick(sender:
AnyObject) {

do {

clientSocket = GCDAsyncSocket()

clientSocket.delegate =
self

clientSocket.delegateQueue =
dispatch_get_global_queue(0,
0)

try
clientSocket.connectToHost(serveripInput.text!,
onPort: serverPort)

conBtn.backgroundColor =
UIColor.blueColor()

}

catch {

print("error")

conBtn.backgroundColor =
UIColor.redColor()

}

}

func socket(sock:
GCDAsyncSocket!, didConnectToHost host: String!, port:
UInt16) {

print("与服务器连接成功!")

clientSocket.readDataWithTimeout(-1, tag:
0)

}

func socketDidDisconnect(sock:
GCDAsyncSocket!, withError err: NSError!) {

print("与服务器断开连接")

}

func socket(sock:
GCDAsyncSocket!, didReadData data: NSData!, withTag tag:
Int) {

// 1
获取客户的发来的数据 ,把 NSData
转 NSString

let readClientDataString:
NSString? = NSString(data: data, encoding:
NSUTF8StringEncoding)

print(readClientDataString!)

// 2
主界面ui 显示数据

dispatch_async(mainQueue, {

let showStr:
NSMutableString = NSMutableString()

showStr.appendString(self.msgView.text)

showStr.appendString(readClientDataString!
as String)

showStr.appendString("\n")

self.msgView.text = showStr
as String

})

// 3.处理请求,返回数据给客户端 ok

let serviceStr:
NSMutableString = NSMutableString()

serviceStr.appendString("ok\n")

clientSocket.writeData(serviceStr.dataUsingEncoding(NSUTF8StringEncoding), withTimeout: -1,
tag: 0)

// 4
每次读完数据后,都要调用一次监听数据的方法

clientSocket.readDataWithTimeout(-1, tag:
0)

}

//发送消息按钮事件

@IBAction func sendBtnClick(sender:
AnyObject) {

// 1.处理请求,返回数据给客户端 ok

let serviceStr:
NSMutableString = NSMutableString()

serviceStr.appendString(self.msgInput.text!)

serviceStr.appendString("\n")

clientSocket.writeData(serviceStr.dataUsingEncoding(NSUTF8StringEncoding), withTimeout: -1,
tag: 0)

}

}

2、SWIFT L/C主要条款的域名号是什么

SWIFT MT700的域名一共有37个,从27开始,到72结束,主要有
45A货物描述
46A单据要求
47A附加条款
等等。

3、swift tcp的连接用什么库

使用SQLiteDatabase操作SQLite数据库 Android提供了一个名为SQLiteDatabase的类,该类封装了一些操作数据库的API,使用该类可以完成对数据进行添加(Create)、查询(Retrieve)、更新(Update)和删除(Delete)操作(这些操作简称为CRUD)。对SQLiteDa...

4、swift3.0 gcdasyncsocket 客户端怎么接收数据

swift代码:需要导入GCDAsyncSocket库文件,可去github下载

import UIKit

class ViewController:
UIViewController,
GCDAsyncSocketDelegate {

@IBOutlet var serveripInput:
UITextField!

@IBOutlet var msgInput:
UITextField!

@IBOutlet var conBtn:
UIButton!

@IBOutlet var sendBtn:
UIButton!

@IBOutlet var msgView:
UITextView!

let serverPort: UInt16 =
9050

var clientSocket:
GCDAsyncSocket!

var mainQueue =
dispatch_get_main_queue()

override func viewDidLoad() {

super.viewDidLoad()

}

//连接服务器按钮事件

@IBAction func conBtnClick(sender:
AnyObject) {

do {

clientSocket = GCDAsyncSocket()

clientSocket.delegate =
self

clientSocket.delegateQueue =
dispatch_get_global_queue(0,
0)

try
clientSocket.connectToHost(serveripInput.text!,
onPort: serverPort)

conBtn.backgroundColor =
UIColor.blueColor()

}

catch {

print("error")

conBtn.backgroundColor =
UIColor.redColor()

}

}

func socket(sock:
GCDAsyncSocket!, didConnectToHost host: String!, port:
UInt16) {

print("与服务器连接成功!")

clientSocket.readDataWithTimeout(-1, tag:
0)

}

func socketDidDisconnect(sock:
GCDAsyncSocket!, withError err: NSError!) {

print("与服务器断开连接")

}

func socket(sock:
GCDAsyncSocket!, didReadData data: NSData!, withTag tag:
Int) {

// 1
获取客户的发来的数据 ,把 NSData
转 NSString

let readClientDataString:
NSString? = NSString(data: data, encoding:
NSUTF8StringEncoding)

print(readClientDataString!)

// 2
主界面ui 显示数据

dispatch_async(mainQueue, {

let showStr:
NSMutableString = NSMutableString()

showStr.appendString(self.msgView.text)

showStr.appendString(readClientDataString!
as String)

showStr.appendString("\n")

self.msgView.text = showStr
as String

})

// 3.处理请求,返回数据给客户端 ok

let serviceStr:
NSMutableString = NSMutableString()

serviceStr.appendString("ok\n")

clientSocket.writeData(serviceStr.dataUsingEncoding(NSUTF8StringEncoding), withTimeout: -1,
tag: 0)

// 4
每次读完数据后,都要调用一次监听数据的方法

clientSocket.readDataWithTimeout(-1, tag:
0)

}

//发送消息按钮事件

@IBAction func sendBtnClick(sender:
AnyObject) {

// 1.处理请求,返回数据给客户端 ok

let serviceStr:
NSMutableString = NSMutableString()

serviceStr.appendString(self.msgInput.text!)

serviceStr.appendString("\n")

clientSocket.writeData(serviceStr.dataUsingEncoding(NSUTF8StringEncoding), withTimeout: -1,
tag: 0)

}

}

5、swift socket.io怎么用

socket.io封装了websocket,同时包含了其它的连接方式,比如Ajax。原因在于不是所有的浏览器都支持websocket,通过socket.io的封装,你不用关心里面用了什么连接方式。你在任何浏览器里都可以使用socket.io来建立异步的连接。

6、ios8 swift CFSocket怎么使用

swiftsocket
https://github.com/xyyc/SwiftSocket

例子
https://github.com/xyyc/SwiftChatServer
https://github.com/xyyc/SwiftChatClient

与swiftsocket解析域名相关的知识