swiftsocket / swiftsocket Goto Github PK
View Code? Open in Web Editor NEWThe easy way to use sockets on Apple platforms
License: BSD 3-Clause "New" or "Revised" License
The easy way to use sockets on Apple platforms
License: BSD 3-Clause "New" or "Revised" License
this library worked perfect but i need check socket is connacted not not. How to check socket ? Is it possibale ? Please, advise me. thanks !
你好想问一下readme 里面讲的拖两个文件进去project是指的udp或者tcp的两个吗,另外一个ysocket.swift需要吗?谢谢!
Both yudpsocket.swift and ytcpsocket.swift won't compile with Swift 2.2 (Xcode 7.3 beta)
Compilation errors refer to Unknown attribute 'asmname', i.e.
/Users/ciukes/dev/MockJsonServerApp/scm/MockJsonServer/Frameworks/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:32:2: Unknown attribute 'asmname'
According to Apple dev forum:
_Swift 2.2 abruptly removed the @asmname attribute in favor of @silgen_name.
https://forums.developer.apple.com/thread/31497
The same information confirmed elsewhere:
tidwall/SwiftWebSocket#28
HI I'm trying to build some app on IoT using swift sockets. iPad will be client and it will send requisitions (for read tags and write commands) for industrial assets and I have some questions, could you help me?
Hi, My problem is socket read only (1024*10) charaters. how to read all lines in swift 2 ?
My code:
private func sendRequest(data: String, client: TCPClient?) -> (String?) {
// It use ufter connection
if client != nil {
// Send data (WE MUST ADD TO SENDING MESSAGE '\n' )
let (isSuccess, errorMessage) = client!.send(str: "(data)\n")
if isSuccess {
// Read response data
let data = client!.read(1024*10)
if let d = data {
// Create String from response data
if let str = NSString(bytes: d, length: d.count, encoding: NSUTF8StringEncoding) as? String {
return (data: str)
} else {
return (data: nil)
}
} else {
return (data: nil)
}
} else {
print(errorMessage)
return (data: nil)
}
} else {
return (data: nil)
}
}
and other question is here :http://stackoverflow.com/questions/34036070/how-to-read-all-lines-in-socket-swift
not able to use library in existing project with Xcode 8 with swift3. Please provide a demo project for ios .
Hello,
I am new in IOS can you please Provide demo project
I am unsure how to create a timeout on a tcp read. I am using it in an application that might not get a response.
Hi, I'm implementing a library that needs a TCP server socket.
apple document dose not complete:
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html
So I found your library, but seems like It's just support Swift > 3
I just need to run a TCP Socket server on a port to connect other device to this port.
sorry for my english ;-)
hi,
I have a problem with your "server socket excample". Iam starting the server on my Macbook and trying to connect with a telnet client running on a virtual machine (ubuntu). the error message is this: "telnet: Unable to connect to remote host: Connection refused". Any idea to solve the problem?
Do you know of a way to get around the string decoding that will work? I am seeing everything else just fine. Just the decoding on the read from my client server is not working.
Hi, I have sent a string to my iOS app which delivers fine, the string is "26" however the iOS app interprets it as [50, 54]. How do I convert this back into a string? I am reading it as let data = client.read(1024).
Thanks
i am using xcode 6.2
when m drag and drop file(s) that you describe in readme file
i stand with so many errors
what should ???
do you provide cocopod or other way to install it ?
or please specifiy how can i slow those problems ?
Hi,
I have developed a class derived from TCPClient to implement some write/read operations with a TCP server on a PLC. The actions I'm intended in perform are:
When I execute each action in distinct button actions it works perfectly, but when I use them into one action at the sequence:
var(success,statusMessage,command) = Client.WriteCommand(CommandValue);
var(success,statusMessage,data1,data2,data3) = Client.ReadData();
it seems the processes doesn't wait until the first line execution and try to execute the second one. It make mess in my protocol communication. Do you know if this lack of synchrony could be solved?
Thanks
Hello,
Can I use this with a SignalR in asp.net?
Regards,
I tried to use this code (client-tcpconnect) in my test-app. How to catch onclose socket event on my client-swift-ios-app? (Server on python) When server is closed while connected.
Can we have Cocoapods support for SwiftSocket?
I'm trying to send a command to an esc/pos, in Javascript, the command would be something like this
PAPER_CUT_A : '\x1d\x56\x41'
but swift do not accept those escape sequences.
I tried something like client.send(data: [0x1d,0x56,0x41])
but that doesn't work either, is there any other way?
Thank you for this, I apologize if this is obvious but I'm only seeing the response header and not the actual response from the server. I'm just using the posted example and printing the response into a UILabel. The response is plain text.
I'm prototyping something and this library is very useful.
UPDATE:
Sorry I mistyped client.read(1024*10) I had some other number inside.
UPDATE 2:
it keeps happening, sometimes returns the headers only and not the data.
Hi,
I'm trying to move to Swift3 and I'm getting error on the following line:
if let addr = String(CString: buff, encoding: String.Encoding.utf8){ //Error here *
tcpClient.addr=addr
}
Thanks
client.read(1024*10) stuck because server didn't close the socket connection!
how to solve it in client side?
Reading this code I constantly see the word "recive". Could we at least get the English language right? It should be "receive" if this wasn't already apparent. This mistake seems to be both in the swift and the c files.
Not working on IPv6 network
怎样知道断线并实现重新链接?
I'm trying to use your framework to communicate with a chatbot application I built that uses Ruby's TCPSocket library. It listens for and responds to simple JSON requests. I love the simplicity of your framework and have a simple client running with it. Though the client receives data just fine, it doesn't seem to send anything to my server.
My server sends back a 'Hello' response whenever a client connects to it. The Swift Code receives this response without any problems when it connects to my server.
But when I attempt to send a request using something like client.send(str: "Hello")
, the Ruby server doesn't get the request. The Swift Code, however, claims it was successful and the code continues. It eventually fails because it has no response from the server to parse.
I've also tried sending the data as UInt8 and NSData, but still get the same result. I don't know what I am missing. My code doesn't seem to send anything to my server no matter what I try.
class ServerCommunicator {
var client: TCPClient
var sessionId: String?
init(){
client = TCPClient(addr: "127.0.0.1", port: 3000 )
connectToServer()
}
func respondTo(input: String) -> String {
println("[App] sending: \(input)")
// Nothing is sent to the server
let (success, errmsg) = client.send(str: input)
if success {
let response = readData()
return response!
}
return ""
}
func connectToServer() {
var (success, errmsg) = client.connect(timeout: 10)
if success {
println("[APP] Connected to \(client)")
// Server sends 'connected' response, client receives data just fine.
readData()
} else {
println(errmsg)
}
}
func readData() -> String? {
let data = client.read(1024*10)
if let serverResponse = data {
if let str = String(bytes: serverResponse, encoding: NSUTF8StringEncoding) {
println("[Server] response: \(str)")
let jsonData = (str as NSString).dataUsingEncoding(NSUTF8StringEncoding)
let response = parseResponse(jsonData!)
sessionId = response.session_id
return response.response
}
}
return nil
}
//...
}
I'm using your socket class in one of my project and it is working fine for un-secure connection. Now we want to use secure connection so I need to know how can we achieve this. So my questions are:
Please reply ASAP.
I have server written on Netty + protobuf to serialize data
So, can i use protobuf library to deserialize data with SwiftSocket library?
Is there a branch or tag available to support Swift 2.3?
Were having other secondary issues with our projects migrating to Swift 3 and looking at alternatives to using this library, but with Swift 2.3.
Is this possible?
I'm trying to add SwiftSocket
to my project (OS X app) using the Cocoapods, but pod install
fails with an error:
[!] The platform of the target
my-app-name
(OS X 10.11) is not compatible withSwiftSocket (1.2)
, which does not supportosx
.
Hello guys,
I'm new to Swift and I'm trying to do the following to build this:
$ swift build
My version:
$ swift --version
Apple Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c)
Target: x86_64-apple-macosx10.9
I'm getting the following errors:
Compiling Swift Module 'ysocket' (3 sources)
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:32:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_connect") func c_ytcpsocket_connect(host:UnsafePointer<Int8>,port:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:32:9: error: expected declaration
@asmname("ytcpsocket_connect") func c_ytcpsocket_connect(host:UnsafePointer<Int8>,port:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:33:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_close") func c_ytcpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:33:9: error: expected declaration
@asmname("ytcpsocket_close") func c_ytcpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:34:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_send") func c_ytcpsocket_send(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:34:9: error: expected declaration
@asmname("ytcpsocket_send") func c_ytcpsocket_send(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:35:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_pull") func c_ytcpsocket_pull(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:35:9: error: expected declaration
@asmname("ytcpsocket_pull") func c_ytcpsocket_pull(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:36:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_listen") func c_ytcpsocket_listen(addr:UnsafePointer<Int8>,port:Int32)->Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:36:9: error: expected declaration
@asmname("ytcpsocket_listen") func c_ytcpsocket_listen(addr:UnsafePointer<Int8>,port:Int32)->Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:37:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_accept") func c_ytcpsocket_accept(onsocketfd:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:37:9: error: expected declaration
@asmname("ytcpsocket_accept") func c_ytcpsocket_accept(onsocketfd:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:33:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_server") func c_yudpsocket_server(host:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:33:9: error: expected declaration
@asmname("yudpsocket_server") func c_yudpsocket_server(host:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:34:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_recive") func c_yudpsocket_recive(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:34:9: error: expected declaration
@asmname("yudpsocket_recive") func c_yudpsocket_recive(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:35:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_close") func c_yudpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:35:9: error: expected declaration
@asmname("yudpsocket_close") func c_yudpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:36:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_client") func c_yudpsocket_client() -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:36:9: error: expected declaration
@asmname("yudpsocket_client") func c_yudpsocket_client() -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:37:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(host:UnsafePointer<Int8>,ip:UnsafePointer<Int8>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:37:9: error: expected declaration
@asmname("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(host:UnsafePointer<Int8>,ip:UnsafePointer<Int8>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:38:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_sentto") func c_yudpsocket_sentto(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:38:9: error: expected declaration
@asmname("yudpsocket_sentto") func c_yudpsocket_sentto(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:32:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_connect") func c_ytcpsocket_connect(host:UnsafePointer<Int8>,port:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:32:9: error: expected declaration
@asmname("ytcpsocket_connect") func c_ytcpsocket_connect(host:UnsafePointer<Int8>,port:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:33:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_close") func c_ytcpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:33:9: error: expected declaration
@asmname("ytcpsocket_close") func c_ytcpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:34:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_send") func c_ytcpsocket_send(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:34:9: error: expected declaration
@asmname("ytcpsocket_send") func c_ytcpsocket_send(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:35:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_pull") func c_ytcpsocket_pull(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:35:9: error: expected declaration
@asmname("ytcpsocket_pull") func c_ytcpsocket_pull(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:36:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_listen") func c_ytcpsocket_listen(addr:UnsafePointer<Int8>,port:Int32)->Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:36:9: error: expected declaration
@asmname("ytcpsocket_listen") func c_ytcpsocket_listen(addr:UnsafePointer<Int8>,port:Int32)->Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:37:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_accept") func c_ytcpsocket_accept(onsocketfd:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:37:9: error: expected declaration
@asmname("ytcpsocket_accept") func c_ytcpsocket_accept(onsocketfd:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:33:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_server") func c_yudpsocket_server(host:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:33:9: error: expected declaration
@asmname("yudpsocket_server") func c_yudpsocket_server(host:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:34:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_recive") func c_yudpsocket_recive(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:34:9: error: expected declaration
@asmname("yudpsocket_recive") func c_yudpsocket_recive(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:35:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_close") func c_yudpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:35:9: error: expected declaration
@asmname("yudpsocket_close") func c_yudpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:36:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_client") func c_yudpsocket_client() -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:36:9: error: expected declaration
@asmname("yudpsocket_client") func c_yudpsocket_client() -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:37:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(host:UnsafePointer<Int8>,ip:UnsafePointer<Int8>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:37:9: error: expected declaration
@asmname("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(host:UnsafePointer<Int8>,ip:UnsafePointer<Int8>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:38:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_sentto") func c_yudpsocket_sentto(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:38:9: error: expected declaration
@asmname("yudpsocket_sentto") func c_yudpsocket_sentto(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:33:36: error: expected '{' in body of function declaration
@asmname("yudpsocket_server") func c_yudpsocket_server(host:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:34:36: error: expected '{' in body of function declaration
@asmname("yudpsocket_recive") func c_yudpsocket_recive(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:35:35: error: expected '{' in body of function declaration
@asmname("yudpsocket_close") func c_yudpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:36:36: error: expected '{' in body of function declaration
@asmname("yudpsocket_client") func c_yudpsocket_client() -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:37:43: error: expected '{' in body of function declaration
@asmname("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(host:UnsafePointer<Int8>,ip:UnsafePointer<Int8>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:38:36: error: expected '{' in body of function declaration
@asmname("yudpsocket_sentto") func c_yudpsocket_sentto(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:32:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_connect") func c_ytcpsocket_connect(host:UnsafePointer<Int8>,port:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:32:9: error: expected declaration
@asmname("ytcpsocket_connect") func c_ytcpsocket_connect(host:UnsafePointer<Int8>,port:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:33:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_close") func c_ytcpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:33:9: error: expected declaration
@asmname("ytcpsocket_close") func c_ytcpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:34:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_send") func c_ytcpsocket_send(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:34:9: error: expected declaration
@asmname("ytcpsocket_send") func c_ytcpsocket_send(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:35:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_pull") func c_ytcpsocket_pull(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:35:9: error: expected declaration
@asmname("ytcpsocket_pull") func c_ytcpsocket_pull(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:36:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_listen") func c_ytcpsocket_listen(addr:UnsafePointer<Int8>,port:Int32)->Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:36:9: error: expected declaration
@asmname("ytcpsocket_listen") func c_ytcpsocket_listen(addr:UnsafePointer<Int8>,port:Int32)->Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:37:2: error: unknown attribute 'asmname'
@asmname("ytcpsocket_accept") func c_ytcpsocket_accept(onsocketfd:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:37:9: error: expected declaration
@asmname("ytcpsocket_accept") func c_ytcpsocket_accept(onsocketfd:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:33:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_server") func c_yudpsocket_server(host:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:33:9: error: expected declaration
@asmname("yudpsocket_server") func c_yudpsocket_server(host:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:34:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_recive") func c_yudpsocket_recive(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:34:9: error: expected declaration
@asmname("yudpsocket_recive") func c_yudpsocket_recive(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:35:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_close") func c_yudpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:35:9: error: expected declaration
@asmname("yudpsocket_close") func c_yudpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:36:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_client") func c_yudpsocket_client() -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:36:9: error: expected declaration
@asmname("yudpsocket_client") func c_yudpsocket_client() -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:37:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(host:UnsafePointer<Int8>,ip:UnsafePointer<Int8>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:37:9: error: expected declaration
@asmname("yudpsocket_get_server_ip") func c_yudpsocket_get_server_ip(host:UnsafePointer<Int8>,ip:UnsafePointer<Int8>) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:38:2: error: unknown attribute 'asmname'
@asmname("yudpsocket_sentto") func c_yudpsocket_sentto(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/yudpsocket.swift:38:9: error: expected declaration
@asmname("yudpsocket_sentto") func c_yudpsocket_sentto(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,ip:UnsafePointer<Int8>,port:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:32:37: error: expected '{' in body of function declaration
@asmname("ytcpsocket_connect") func c_ytcpsocket_connect(host:UnsafePointer<Int8>,port:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:33:35: error: expected '{' in body of function declaration
@asmname("ytcpsocket_close") func c_ytcpsocket_close(fd:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:34:34: error: expected '{' in body of function declaration
@asmname("ytcpsocket_send") func c_ytcpsocket_send(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:35:34: error: expected '{' in body of function declaration
@asmname("ytcpsocket_pull") func c_ytcpsocket_pull(fd:Int32,buff:UnsafePointer<UInt8>,len:Int32,timeout:Int32) -> Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:36:36: error: expected '{' in body of function declaration
@asmname("ytcpsocket_listen") func c_ytcpsocket_listen(addr:UnsafePointer<Int8>,port:Int32)->Int32
^
/Users/ivan/projects/github/SwiftSocket/SwiftSocket/ysocket/ytcpsocket.swift:37:36: error: expected '{' in body of function declaration
@asmname("ytcpsocket_accept") func c_ytcpsocket_accept(onsocketfd:Int32,ip:UnsafePointer<Int8>,port:UnsafePointer<Int32>) -> Int32
^
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2015-12-01-a.xctoolchain/usr/bin/swift-build-tool", "-f", "/Users/ivan/projects/github/SwiftSocket/SwiftSocket/.build/debug/SwiftSocket.o/llbuild.yaml"]
Is there anything I am doing wrong?
Thanks.
Do you know a software that I can use in Mac OS X El Captain to monitor and list socket operations, when using iPad Simulator on XCode? I need to see if operations are being executed in correct order. Thanks
Thank you very much for great effort.
I connect to Java server. server receive string message correctly.
when server reply to me with string message, callback is called but data,remoteip,remoteport are nil
I use this code :
func testudpserver(){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), { () -> Void in
var server:UDPServer=UDPServer(addr:"127.0.0.1",port:19876)
var run:Bool=true
while run{
var (data,remoteip,remoteport)=server.recv(1024)
println("recive")
if let d=data{
if let str=String(bytes: d, encoding: NSUTF8StringEncoding){
println(str)
}
}
println(remoteip)
server.close()
break
}
})
}
I've installed SwiftSocket using CocoaPods but it won't compile for OS X. I've included OS X version in the Podfile, 10.12:
static var Sender = TCPClient(address: "127.0.0.1", port: 8080 )
Error is 'use of unresolved identifier TCPClient.
any thoughts appreciated.
I am reading from a TCP data stream in a loop. Is there anyway to check if the connection gets disconnected after being successfully established?
Hi guys,
Is there some version of SwiftSocket compatible with Swift 2.3?
Thanks
I recently have used your library and found your method to convert return data byte arrays to strongs is no longer working with Swift because String.stringWithBytes is not longer part of the String class.
This is your example which no longer works
var data = client.read(1024*10)
if let d = data {
if let str = String.stringWithBytes(d, length: d.count, encoding: NSUTF8StringEncoding){
println(str)
}
My Change / Fix suggestion
let data = client.read(1024*10)
if data != nil {
str = NSString(bytes: data!, length: data!.count, encoding: NSUTF8StringEncoding)
println(str)
}
To display the returned data (NSString) in a text box I used casting
textBox.text = String(str)
or in one call you can use
textBox.text = String(NSString(bytes: data!, length: data!.count, encoding: NSUTF8StringEncoding))
I tried to make a pull request but I couldn't work out how it worked (sorry im still learning how GitHub works)
Hope this helps someone as it had be caught up for quite some time!
When I add the ysocket.framework and build, it shows the error " clang: error: linker command failed with exit code 1 (use -v to see invocation)". How can I solve this? thank you
Hi,
how can I prevent a runtime error in the read process triggered by a network disconnect?
I can't use TCPServer without give an IP address.
For example in Java, I can write this : ServerSocket ss = new ServerSocket(4444);
With SwiftSocket, I would like to write this : let server:TCPServer = TCPServer(port:4444)
Is there any date to release a version with support to SPM?
Hi,
I've develop based on swift socket a client class that implements one simple protocol, but I want to use 2 client instances objects in my app, one to do cyclic connections and another to do command connections. My server accepts more than one connection and also are able to process clients requisitions without a problem. My question is how I can guarantee that each client do only one connection, that is, how do you suggest to avoid perform a conect to server, it that instance is already connected? Thanks.
import SwiftSocket
And then use the TCPClient() function
you can see the error 'not found'
I use TCPClient.read() to read responses from a mpd server.
The server itself sends more than, e.g. 2048 Bytes but I only receive 1448 Bytes:
if let responseData = self.client.read(self.DATALEN) {
print("Len: \(responseData.count)")
response = String.init(bytes: responseData, encoding: String.Encoding.utf8)
}
I'm new in swift.
And I try the example.
//Read data.
var data=socket.read(1024*10)
Here, I don`t know the length of data, how can I write the parameter instead of '1024*10' ?
Thanks very much !
please update to support ipv6 to..
thanks
After starting my app, I can connect a TCP Client to my server and send one or two messages using client.sent(str: "test"). When trying to send more, it keeps throwing "send error"s. This is due strlen() of the string that is to be sent is different from the sendsize. Why does that happen?
Is it based on Grand Central Disptach?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.