Hi,
i'm doing some network coding with the built-in library, and come to an abrupt halt due to limitations in this lib. What i want is to connect, as a client, to several servers at the same time. As i understand it, you can only connect to one server at a time as a client as it is now. Why do i want to connect to more than one server at a time? Well all servers are not able to service me at my top bandwidth, so why waste bandwidth when i could connect to more servers to take up the slack. If this is possible with the current library then could someone please explain how it's done, i for one could not find the solution. I'll provide some sample code to explain what i want:
Code: Select all
*buffer = AllocateMemory(0, 2048, 0)
EOL.s=Chr(13)+Chr(10)
httpheader1.s="GET /download/PureBasic.lha HTTP/1.1"+EOL
httpheader1+"Host: [url]http://www.purebasic.com[/url]"+EOL+EOL
httpheader2.s="GET /download/PureBasic_Update_3.00.zip HTTP/1.1"+EOL
httpheader2+"Host: [url]http://www.purebasic.com[/url]"+EOL+EOL
clientID1 = OpenNetworkConnection("[url]http://www.purebasic.com[/url]", 80)
clientID2 = OpenNetworkConnection("[url]http://www.purebasic.com[/url]", 80)
; I open connection to the same host but it's just an example
; might as well be a completely different host.
fin1 = #TRUE : fin2 = #TRUE
If clientID1
SendNetworkData(clientID1, @httpheader1, Len(httpheader1))
CreateFile(1,"PureBasic_Update_3.00.zip.download") : fin1 = #FALSE
EndIf
If clientID2
SendNetworkData(clientID2, @httpheader2, Len(httpheader2))
CreateFile(2, "PureBasic.lha.download") : fin2 = #FALSE
EndIf
Repeat
clientevent = NetworkClientEvent()
If clientevent
clientID = NetworkClientID()
If clientID = clientID1
length = ReceiveNetworkData(clientID1, *buffer, 2048)
UseFile(1)
WriteData(*buffer, length)
if length<2048 : fin1=#TRUE : CloseFile(1) : EndIf
EndIf
If clientID = clientID2
length = ReceiveNetworkData(clientID2, *buffer, 2048)
UseFile(2)
WriteData(*buffer, length)
If length<2048 : fin2 = #TRUE : CloseFile(2) : EndIf
EndIf
EndIf
Delay(20)
Until fin1 and fin2