@@ -35,8 +35,22 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) {
3535 {
3636 ServerDrv::startClient (uint32_t (ip), port, _sock);
3737 WiFiClass::_state[_sock] = _sock;
38- while (!connected ());
38+
39+ unsigned long start = millis ();
40+
41+ // wait 4 second for the connection to close
42+ while (!connected () && millis () - start < 10000 )
43+ delay (1 );
44+
45+ if (!connected ())
46+ {
47+ Serial.println (" timeout on client connection" );
48+ return 0 ;
49+ }
50+ else
51+ Serial.println (" CONNECTED" );
3952 }else {
53+ Serial.println (" No Socket available" );
4054 return 0 ;
4155 }
4256 return 1 ;
@@ -94,8 +108,12 @@ int WiFiClient::read(uint8_t* buf, size_t size) {
94108}
95109
96110int WiFiClient::peek () {
97- // TODO to be implemented
98- return 0 ;
111+ uint8_t b;
112+ if (!available ())
113+ return -1 ;
114+
115+ ServerDrv::getData (_sock, &b, 1 );
116+ return b;
99117}
100118
101119void WiFiClient::flush () {
@@ -112,10 +130,11 @@ void WiFiClient::stop() {
112130
113131 unsigned long start = millis ();
114132
133+
115134 // wait a second for the connection to close
116135 while (status () != CLOSED && millis () - start < 1000 )
117136 delay (1 );
118-
137+ Serial. print ( " Stop client! Status: " );Serial. println ( status (), 10 );
119138 _sock = 255 ;
120139}
121140
@@ -125,7 +144,12 @@ uint8_t WiFiClient::connected() {
125144 return 0 ;
126145 } else {
127146 uint8_t s = status ();
128-
147+ /*
148+ if (s== SYN_SENT) Serial.print("*");
149+ else{
150+ Serial.print("Status:"); Serial.println(s,10);
151+ }
152+ */
129153 return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
130154 s == FIN_WAIT_2 || s == TIME_WAIT ||
131155 s == SYN_SENT || s== SYN_RCVD ||
0 commit comments