Why does this code not work?
As you can see I set my own timeout but instead out is printed 20 seconds later after i call my connect function. I notice also that if i use udp it will say its connected even if the ip cannot be reached. is this a bug?
Framework BRL.Socket Import BRL.System Import BRL.SocketStream Import BRL.StandardIO Function Connect(serverIP$,port,timeout) Local serverIPN = IPtoInt(serverIP$) Local socket=CreateTCPSocket() Local connect=ConnectSocket(socket,serverIPN,port) Local starttime=MilliSecs() Repeat endtime=MilliSecs() passedtime=(endtime-starttime) Until passedtime >= timeout Or connect If passedtime >= timeout connect=2 Else Local stream=CreateSocketStream(socket) EndIf Return connect Function IPtoInt(serverIP$) serverIP$:+"." Local sect:String[4] For i = 0 To 3 part = serverIP$.find(".") sect[i] = serverIP$[0..part] serverIP$ = serverIP$[part+1..] Next Return (sect[0].toint() Shl 24) + (sect[1].toint() Shl 16) + (sect[2].toint() Shl 8) + sect[3].toint() End Function End Function time=MilliSecs() out=connect("82.2.199.245",80,1000) Print out timepassed=MilliSecs()-time Print timepassed
As you can see I set my own timeout but instead out is printed 20 seconds later after i call my connect function. I notice also that if i use udp it will say its connected even if the ip cannot be reached. is this a bug?