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

swift ios使用可能存在漏接收数据的情况,应该怎么处理? #806

Closed
JoyGY opened this issue Sep 15, 2017 · 29 comments
Closed
Labels

Comments

@JoyGY
Copy link

JoyGY commented Sep 15, 2017

My project is swift,xcode8.3,swift3.1 。
I felt as if there is leakage of data, because the android there can be the received data, I here can only receive a part of, and I see in the Log output that has that part did not receive the data, but in on (" data ") {(data, ack)} in the callback method that part did not receive the data。
I don't know if anyone has encountered similar problems. What's the solution? Thank you!

我觉得好像有漏接数据的情况,因为android可以接收到的数据在我这里(ios)只能接收的一部分,但是我在日志输出的数据里面有看到我没有接收到的那部分数据,但是在on (" data ") {(data, ack)} 的回调方法中却没有接收到 。
不知道有没有人遇到过类似的问题,请问有什么解决思路提供,谢谢!

@nuclearace
Copy link
Member

I don't quite understand the issue. What do you mean leakage of data? I've never seen anything like that. What transport was being used here?

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

let socket = SocketIOClient(socketURL: URL(string: "my sever url")!, config: [.log(true)])

socket.emit("data", ["position"])
socket.on("data") { (data, ack) in
    print("-get-data--message---**\(data)---**\(ack)")
}

I am using the above setting method, but I get to the data in the print is not all, sometimes interface transmit to the amount of data are large, in this method did not show receiving data, but through the inside of the underlying file you have seen this data in the Log output.
I am not sure whether my own setting has the problem or what other reason, I hope you can guide, thank you!

我用的是以上的设置方法,但是我在print中获取到的data数据并不是全部的,有的时候接口传输过来的数据量很大很大的时候,在这个方法中却没有显示接收数据,但是通过您底层文件里面的Log输出中却有看到这数据。

我不确定是不是我自己的设置有问题还是什么其他的原因,希望您指导一下,谢谢

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

2017-09-18 11:14:30.543 XFAWealthForPC[41927:15457164] LOG SocketIOClient: Emitting: 2["data",["position"]] 2017-09-18 11:14:30.543 XFAWealthForPC[41927:15457363] LOG SocketEngine: Writing ws: 2["data",["position"]] has data: false 2017-09-18 11:14:30.543 XFAWealthForPC[41927:15457164] LOG SocketIOClient: Adding handler for event: data 2017-09-18 11:14:30.543 XFAWealthForPC[41927:15457363] LOG SocketEngine: Sending ws: 2["data",["position"]] as type: 4 2017-09-18 11:14:32.547 XFAWealthForPC[41927:15457363] LOG SocketEngine: Got message: 42["data",{"name":"position","account":"GZA2017","data":[{"0":"000001","3":9.7,"4":800,"10":"GZA2017","20":"SZSE","21":"PAB","22":"1","23":"CNY","31":9.52,"73":"SPREAD_SZSE_11","115":9.52,"505":"平安银行","1504":1,"1508":"0","bodAmount":7616,"bodQuantity":800,"bodShortQuantity":0,"realizedPL":0,"unrealizedPL":143.99999999999977,"bodPL":143.99999999999977,"execPL":0,"costPrice":9.52,"totalQuantity":800,"totalAmount": ......

This is the Log output which I get the data, but I am in func on (event: String callback: @escaping _, NormalCallback) - > UUID {} This method is not available in this part of the data, I want to know if I want to get this part of the data should be how to do

这是我获取到的Log输出里面的数据,但是我在func on(_ event: String, callback: @escaping NormalCallback) -> UUID {} 这个方法中却获取不到这部分数据,我想知道如果我想得到这部分数据应该怎么做

@nuclearace
Copy link
Member

@JoyGY one thing I see is that you're adding handlers while the socket is running. This is generally a bad idea, since there's always the possibility that the handler would be added after the event is received. You should add all handlers before calling connect.

@nuclearace
Copy link
Member

#766 reference this

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

I tried this way today, but it doesn't work,are there any other solutions?

@nuclearace
Copy link
Member

Are you seeing the event you're looking for in the log output? You should see your event in the logs followed by a message that looks like "Got binary data: ..."

@nuclearace
Copy link
Member

That's if you're actually sending Buffers from the server. What version of socket.io are you using on the server?

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

I use 11.1.3 today, before using the 11.1.2. But they have the same problem.

@nuclearace
Copy link
Member

Also, the log posted above does show getting an event named "data" however it doesn't include the rest of the lifecycle of that event. Does it make it through the parses? You should see a log line that says the client is attempting to handle data.

@nuclearace
Copy link
Member

@JoyGY I mean what server version? 2.0.x?

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

This log to get the data, I think may be because the data volume is too big, at the time of parsing may be intercepted, so the method to get data and can't get to the data, I hope that I get the data in the method of the content of the log output!

Now I don't know what the server version is on my side, I can ask the server side version tomorrow.May is the latest version.

@nuclearace
Copy link
Member

nuclearace commented Sep 18, 2017

@JoyGY Are you saying that the log cuts out trying to print the message for that event? I think I remember seeing that somewhere...

@nuclearace
Copy link
Member

If that's not it, I'm not really understanding the issue. Are you saying that your data event doesn't have all the data that you expect, but that you are getting a data event?

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

2017-09-18 20:55:46.530 XFAWealthForPC[85021:16877153] LOG SocketEngine: Got message: 42["auth",true] 2017-09-18 20:55:46.531 XFAWealthForPC[85021:16877153] LOG SocketIOClient: Should parse message: 2["auth",true] 2017-09-18 20:55:46.651 XFAWealthForPC[85021:16876586] LOG SocketParser: Parsing 2["auth",true] 2017-09-18 20:55:46.651 XFAWealthForPC[85021:16876586] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [auth, 1]; id: -1; placeholders: -1; nsp: /} 2017-09-18 20:55:46.652 XFAWealthForPC[85021:16876586] LOG SocketIOClient: Handling event: auth with data: [1] 2017-09-18 20:55:46.667 XFAWealthForPC[85021:16877162] LOG SocketEngine: Got message: 42["data",{"name":"position","account":"GZA2017","data":[{"0":"000001","3":9.65,"4":800,"10":"GZA2017","20":"SZSE","21":"PAB","22":"1","23":"CNY","31":9.52,"73":"SPREAD_SZSE_11","115":9.52,"505":"平安银行","1504":1,"1508":"0","bodAmount":7616,"bodQuantity":800,"bodShortQuantity":0,"realizedPL":0,"unrealizedPL":104.00000000000063,"bodPL":104.00000000000063,"execPL":0,"costPrice":9.52,"totalQuantity":800,"totalAmount":7616,"todayBuyAmount":0,"todayBuyQuantity":0,"todaySellAmount":0,"todaySellQuantity":0,"depositAmount":0,"depositQuantity":0,"withdrawAmount":0,"withdrawQuantity":0,"bod":{"0":"000001","4":"800","10":"GZA2017","38":"0","115":"0","470":"0","schema":{"header":{},"symbol":{"tag":0},"bid":{"tag":1},"ask":{"tag":2},"price":{"tag":3},"quantity":{"tag":4},"status":{"tag":5},"orderNo":{"tag":6},"exchNo":{"tag":7},"tranNo":{"tag":8},"request":{"tag":9},......

I am got data, in this message "LOG SocketEngine: Got message: 42" ,But you can't get in this method
open func on(_ event: String, callback: @escaping SocketIO.NormalCallback) -> UUID

But sometimes I can also be obtained from the above the method to transmit the data, may be because of the relatively small amount of data, so can make a successful resolution.I guess you have set over there if access to parse the data content too much time there will be a problem, cannot successfully returns to on method.This is just my guess, don't know right.As the Log output data is a bit more, so only part of the, today is roughly measuring the amount of data: the number of string a total of 69441. But after may transmit more data.

但是有的时候我也可以从以上这个方法中获取到服务器传递过来的数据,可能是因为数据量比较小,所以能解析成功。我猜想是不是您那边有设置如果获取到的数据内容太多的时候解析的时候会有问题,不能成功返回到on方法中。这仅仅是我的猜测,不知道对不对。由于Log输出的数据有点多,所以只截取了一部分,今天大致测了一下数据量:字符串数量一共69441. 但是以后可能会传输更多的数据。

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

我的意思是socket传输过来的所有数据,有一部分我能接收到,但是有一部分不能接收到,但是不能接收到的那部分数据可以在底层的Log输出中看到,因此我猜想是不是因为那部分数据数据量太大所以不能正确的返回到on的回调方法中
I mean all the data transmission over the socket, there's a part of me will receive, but have not received a part, but the part of the not received data to be seen in the bottom of the Log output, so I guess it is probably part of the data is too big so you can't return to the correct callback the on method

@nuclearace
Copy link
Member

Hm, I'm not sure what more I can do. My only suggestion would be to start debugging the client and see where things are failing.

This is where the Engine gets the string data and parses it: https://github.com/socketio/socket.io-client-swift/blob/master/Source/SocketIO/Engine/SocketEngine.swift#L503
This is where the client turns the engine string into something that can be handled by the client: https://github.com/socketio/socket.io-client-swift/blob/master/Source/SocketIO/Parse/SocketParsable.swift#L71

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

I'm very sorry, my English is not very good, please forgive me. I have another question. I want to know if you have any restrictions on the big data you transfer over there. For example, more than a few bytes will not be returned, or anything else.

Because of the same data, Android can receive it back there, but the IOS can only be displayed in Log, and cannot be obtained in the callback method of the on method。

@nuclearace
Copy link
Member

@JoyGY No worries about the english. You say it can only be displayed in the log? If that's the case here's some things you can look for:

Look for messages that say "Parsing: 2["data"......]". That's where the client is creating the packets to call event handlers with. At the end of those messages it should print the created packet or some ERROR log line.

@nuclearace
Copy link
Member

There shouldn't be any limitation that I know of regarding how large a payload could be, except maybe Int.max items. Which would probably cause problems for the server before the client.

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

2017-09-18 20:55:41.257 XFAWealthForPC[85021:16877189] LOG SocketEngine: Sending ws: 2["auth","7Tkv92r-EozasekjT0R4j3ycVCrWe3LK.TY5IHL7198PiEM\/tbib0yjMMv\/uCJzQqSNGDNiGZKQs"] as type: 4 2017-09-18 20:55:46.502 XFAWealthForPC[85021:16876586] LOG SocketIOClient: Emitting: 2["data","position"] 2017-09-18 20:55:46.506 XFAWealthForPC[85021:16876586] LOG SocketIOClient: Adding handler for event: data 2017-09-18 20:55:46.506 XFAWealthForPC[85021:16877171] LOG SocketEngine: Writing ws: 2["data","position"] has data: false 2017-09-18 20:55:46.506 XFAWealthForPC[85021:16876586] LOG SocketParser: Parsing 2["auth",false] 2017-09-18 20:55:46.506 XFAWealthForPC[85021:16877171] LOG SocketEngine: Sending ws: 2["data","position"] as type: 4 2017-09-18 20:55:46.507 XFAWealthForPC[85021:16876586] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [auth, 0]; id: -1; placeholders: -1; nsp: /} 2017-09-18 20:55:46.507 XFAWealthForPC[85021:16876586] LOG SocketIOClient: Handling event: auth with data: [0] socket --gy-- auth --22--**[0]---**<SocketIO.SocketAckEmitter: 0x60000023aa80> 2017-09-18 20:55:46.530 XFAWealthForPC[85021:16877153] LOG SocketEngine: Got message: 42["auth",true] 2017-09-18 20:55:46.531 XFAWealthForPC[85021:16877153] LOG SocketIOClient: Should parse message: 2["auth",true] 2017-09-18 20:55:46.651 XFAWealthForPC[85021:16876586] LOG SocketParser: Parsing 2["auth",true] 2017-09-18 20:55:46.651 XFAWealthForPC[85021:16876586] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [auth, 1]; id: -1; placeholders: -1; nsp: /} 2017-09-18 20:55:46.652 XFAWealthForPC[85021:16876586] LOG SocketIOClient: Handling event: auth with data: [1] socket --gy-- auth --22--**[1]---**<SocketIO.SocketAckEmitter: 0x608000230ae0> 2017-09-18 20:55:46.667 XFAWealthForPC[85021:16877162] LOG SocketEngine: Got message: 42["data",{"name":"position","account":"GZA2017","data":[{"0":"000001","3":9.65,"4":800,"10":"GZA2017","20":"SZSE","21":"PAB","22":"1","23":"CNY","31":9.52,"73":"SPREAD_SZSE_11","115":9.52,"505":"平安银行","1504":1,"1508":"0","bodAmount":7616,"bodQuantity":800,"bodShortQuantity":0,"realizedPL":0,"unrealizedPL":104.00000000000063,"bodPL":104.00000000000063,"execPL":0,"costPrice":9.52,"totalQuantity":800,"totalAmount":7616,"todayBuyAmount":0,"todayBuyQuantity":0,"todaySellAmount":0,"todaySellQuantity":0,"depositAmount":0,"depositQuantity":0,"withdrawAmount":0,"withdrawQuantity":0,"bod":{"0":"000001","4":"800","10":"GZA2017","38":"0","115":"0","470":"0","schema":{"header":{},"symbol":{"tag":0},"bid":{"tag":1},"ask":{"tag":2},"price":{"tag":3},"quantity":{"tag":4},"status":{"tag":5},"orderNo":{"tag":6},"exchNo":{"ta....

I carefully looked at the output data of Log, LOG SocketParser: Parsing 2["auth" false] is to obtain “auth” validation data before, after successfully sent ["data", "position"], then the returned data is required to display the data

@nuclearace
Copy link
Member

Again, your log output cuts out before it shows any messages about parsing the "data" event. It looks like it is emitting events for "auth", but without the rest of the log I can't see what it's doing.

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

let socketGY = SocketIOClient(socketURL: URL(string: "my sever url")!, config: [.log(true)])

      socketGY.on(clientEvent: .connect) {data, ack in
            //Verification auth
            socketGY.emit("auth", UserVerifySessionId)

           //send request message
            socketGY.emit("data", with: ["position"])

           //get data
            socketGY.on("data", callback: { (data , ack) in
                print("data = \(data)")
            })
        }

    socketGY.connect()

This is the code that I use socketIO

I want to ask, what kind of solution do you recommend to meet such a problem?
1., if you really get the data parsing process, because the amount of data is too large to cause no return, is it necessary for me to modify your underlying source code?
2., if there is data from the Log output that indicates the transfer, does that mean that the data is received here, but that there is a problem in parsing the data to the return method?
3. although it can receive data, sometimes can not receive data, it may be that server data transmission problem? For example, when a large amount of data and a small amount of data transmission in different ways, resulting in receiving data, the data can not be returned to normal?
4., the server is using the socketIO over there. If the client receives data on this side all the time, what other third party replacement can you use? What do you recommend?

我想问一下,遇到这样的问题,您推荐什么样的解决思路?
1.如果真的是获取到数据解析的过程因为数据量太大而导致没有办法返回的话,是不是我需要修改您的底层源码?
2.如果从Log输出中有显示传输过来的数据,那是不是说明这边接收到了数据,但是在解析数据到返回方法中出了问题?
3.虽然有的时候能接收到数据,有的时候不能接收数据,那可能会是服务器那边传输数据的问题吗?比如数据量大和数据量小的时候的传输方式不同,导致接收数据的时候,对大的数据无法正常返回?
4.服务器那边使用的是socketIO,如果客户端这边接收数据一直有问题,可以使用什么其他的第三方替换吗?您有什么推荐吗?

@nuclearace
Copy link
Member

@JoyGY In that code example, is this socket inside of a function or method? Or is it a global variable? Either way, you should put the .on("data"....) before the emits.

Regarding your questions:

  1. There shouldn't be anything that's limiting the size of the data, unless there's something I don't know about.
  2. If you see in the log that the "data" event is being received, but your handler isn't being called, that could mean something is happening in the parse phase.
  3. Maybe.
  4. I don't know of any other socket.io clients that are for socket.io 2.0 and native iOS.

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

I try this way put the .on("data"....) before the emits.But isn't work.

If the request method is same, but the received data can be successfully resolved some normal return but only some of the Log output and back can not, it is not that the received data format is different?
If that's the problem above, then it's the data transfer over the server, right?

如果请求方法相同,但是接收到的数据有的能解析成功正常返回,但是有的只能在Log中输出并不能成功返回,那是不是说明接收到的数据格式是不同的?

如果是上面的问题的话,那就说明是服务器那边传输数据的问题了对吧?

@nuclearace
Copy link
Member

Yeah I'm not sure, you'll have to debug the client to see what's happening. But just to clarify, your socket is a global variable or attached to a class instance? It's not just declared in a function? Because if it's not in a global variable or class instance it'll be reclaimed by ARC.

@JoyGY
Copy link
Author

JoyGY commented Sep 18, 2017

my socket is a global variable ,Don't worry, it will be reclaimed by ARC.

It's 2 in the morning, so I can only try again tomorrow, thank you for your patience, thank you very much

@JoyGY
Copy link
Author

JoyGY commented Sep 19, 2017

I'm very sorry, I studied the problem carefully, and asked the server developer questions about the data, in fact your framework is no problem, the server returns the data which has a return value is 5e-324, when using JSON analytical system, because the data with the decimal point is too long, that NSNmber is not fit to data offside.

Reference URL: http://blog.csdn.net/jijiji000111/article/details/52471000,
then the server management modify the return value, data analysis is successful,

Sorry for the trouble you have caused us, I'm really so sorry.

@JoyGY JoyGY closed this as completed Sep 19, 2017
@JoyGY JoyGY reopened this Sep 19, 2017
@nuclearace
Copy link
Member

@JoyGY No problem, glad you got it sorted out.

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

No branches or pull requests

2 participants