Hi all,
Im doing a API using socket.io. I want to store one of the line from final class into my button action which is " socket.emit("Server Port","Hi server111")". When i declare the " socket.emit("Server Port","Hi server111")".
The code is working and will send the msg when connected to server. What I am trying to do is to do a continuous send to server after connected which I am stuck at.
My last line of code have an error Value of type '(Int32, Int32, Int32) -> Int32' has no member 'emit'
Thank you for reading.
final class Service: ObservableObject {
private var manager = SocketManager(socketURL: URL(string:"ws://localhost:4005")!, config:[.log(true), .compress])
init(){
let socket = manager.defaultSocket
socket.on(clientEvent: .connect){ (data, ack) in //connect and send/emit
print("Connected")
DispatchQueue.main.async{
socket.emit("Server Port","Hi server111")
}}
struct ContentView: View {
var body: some View {
@ObservedObject var service = Service()
VStack{
Text("Received messages from Node.js")
.font(.largeTitle)
TextField("Type Smth:", text: $test)
Text("Output: \(test)")
Button("Save", action:{
socket.emit("Server Port","Hi server111") // <<--