Open bobongski opened 5 years ago
I need a bit more info to be able to troubleshoot this. Any chance you can post some code that illustrates the problem? Thanks.
func loadServer(){
self.mySocket = try! Socket.create(family: .inet, type: .stream, proto: .tcp)
//self.mySocket = try! Socket.create(family: .inet6)
self.mySocket?.readBufferSize = 32768
do {
try mySocket!.connect(to: "localhost", port: 50694)
var message = Data()
let _ = try mySocket!.read(into: &message)
if let string = String(data: message, encoding: .utf8) {
let xml = try! XML.parse(string)
// print("xml \(xml["ResultSet"])")
//xml.ResultSet
if let text = xml["Result", "CardNumber"].text {
print(text)
}
lblTest.text = string
}else{
lblTest.text = "connected"
}
// mySocket.write(from:, to: address)
// lblTest.text = "connected"
// try mySocket!.write(from: "testing")
} catch let error {
lblTest.text = "An error occurred: \(error.localizedDescription)"
}
}
@IBAction func actionWrite(_ sender: Any) {
print("actionWrite")
do {
try mySocket!.write(from: "testing")
} catch let error {
print("actionWrite \(error.localizedDescription)")
}
}
Loading server works fine but after I try to write it it has a Socket Error.
The operation couldn’t be completed. (Socket.Socket.Error error 1.)
Any thoughts @billabt ?
Can you try it outside the simulator? I think permissions might be getting in the way when you use the simulator...
This article helped me.. For anyone else getting errors when trying to open a connect on a Mac app, make sure you allow "Outgoing Connections (Client)" in "Signing & Capabilities"
I tried TCP using simulator and try sending string to my NIO server but in my server it wont go inside my function channelRead.