Open panayiotis95 opened 7 years ago
@panayiotis95 I have the same problem and i find the reason of showing -1 . If you read the file ytcpsocket.c
, you will notice the following function :
int ytcpsocket_pull(int socketfd, char *data, int len, int timeout_sec) {
int readlen = 0;
int datalen = 0;
if (timeout_sec > 0) {
fd_set fdset;
struct timeval timeout;
timeout.tv_usec = 0;
timeout.tv_sec = timeout_sec;
FD_ZERO(&fdset);
FD_SET(socketfd, &fdset);
int ret = select(socketfd + 1, &fdset, NULL, NULL, &timeout);
if (ret <= 0) {
return ret; // select-call failed or timeout occurred (before anything was sent)
}
}
// use loop to make sure receive all data
do {
readlen = (int)read(socketfd, data + datalen, len - datalen);
printf("%d\n",readlen); // -1 is generated from here , an read error occured
if (readlen > 0) {
datalen += readlen;
}
} while (readlen > 0);
return datalen;
}
But i don't know how to solve it. @danshevluk help us ,please
Hello there! Which version of SwiftSocket are you using?
@danshevluk version 2.0.2
-> SwiftSocket (2.0.2)
A cool framework to work with TCP and UDP sockets
pod 'SwiftSocket', '~> 2.0.2'
- Homepage: https://github.com/swiftsocket/SwiftSocket
- Source: https://github.com/swiftsocket/SwiftSocket.git
- Versions: 2.0.2, 2.0.1, 2.0, 1.2, 1.1 [master repo]
Some one description
any update?
I believe this issue occurs only in version v2.0.2. The iOS example runs as expected in all previous versions.
I have the same problem and I resolve the issue by specifying the timeout parameter.
guard let MsgBytes = tcpClient.read(4, timeout: 5) else { return; }
danshevluk is disappear or go to Hawaii for travelling ? 😄
still not working
how to install early version?
I configure raspberry pi as tcp server that waits for connection gets the data and then send it back. On swift I copy and paste the example client code in readme file of swiftsocket. The connection is established raspberry receives the data send but ios only shows -1 in xcode terminal