Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How we can connect wifi printers? #70

Open
SHEBINKUNIYIL opened this issue May 16, 2023 · 2 comments
Open

How we can connect wifi printers? #70

SHEBINKUNIYIL opened this issue May 16, 2023 · 2 comments

Comments

@SHEBINKUNIYIL
Copy link

How we can connect wifi printers?

@YanVetrov
Copy link

Example of direct tcp connection

import Network
import MobileCoreServices

                let PORT = NWEndpoint.Port(printerPort)
                let ipAddress = NWEndpoint.Host(printerIP)
                let queue = DispatchQueue(label: "TCP Client Queue")

                let tcp = NWProtocolTCP.Options.init()
                tcp.noDelay = true
                let params = NWParameters.init(tls: nil, tcp: tcp)
        connection = NWConnection(to: NWEndpoint.hostPort(host: ipAddress, port: PORT ?? 9100), using: params)
        connection?.stateUpdateHandler = { (newState) in

                    switch (newState) {
                    case .ready:
                        print("Socket State: Ready")
                        UserDefaults.standard.set(true, forKey: "isConnected")
                    default:
                        UserDefaults.standard.set(false, forKey: "isConnected")

                        break
                    }
                }
        connection?.start(queue: queue)

    func sendMSG(_ content:Data? = nil) {
           print("send data")
        connection?.send(content: content, completion: NWConnection.SendCompletion.contentProcessed(({ (NWError) in
               if (NWError == nil) {
                   print("Data was sent to TCP destination ")
                   
               } else {
                   print("ERROR! Error when data (Type: Data) sending. NWError: \n \(NWError!)")
               }
           })))
       }

@SHEBINKUNIYIL
Copy link
Author

thank you for the update,
but Arabic text and image,s not printing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants