Client recieves data, but isn't sending data
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 forgot to mention that the Ruby application is not an HTTP server. It's a basic socket app that listens on port 3000 and responds to JSON data sent to it.
I also meet the same issue.
Anyone got solution for issue. i am also getting same issue.
To send message to server from ios client message must be end with "\n".
i'm also writing a similar chat app, receiving data from chat server shows as "-1" from swiftsocket's default iOS example, any ideas?
1 year passed. ok after too longtime finding ideal, i will change to other lib