Page 1 of 1

Posted: Thu Apr 04, 2002 9:37 am
by BackupUser
Restored from previous forum. Originally posted by Pupil.

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
I've never coded network stuff before so i might be totaly wrong -if so please correct me..

Posted: Thu Apr 04, 2002 9:12 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

Hi!

I know your problem and I asked Fred for some more Commands a long time ago.
I searched for some workarounds and now I'm doing it the following way:

It is possible to connect to more then one server using the PBNetwork lib. OpenNetworkConnection returns a socket number which is importend to know.

Opening more connections is possible with this command. Now use WSAAsyncSelect_ to attach a NetworkEvent to a Window. For this you need the SocketNumber and a set of actions like e.g. Accept etc.

Use WaitMessage_() instead of WaitWindowEvent() or something like that.

Some CodeSnip out of my Code:

If WSAAsyncSelect_(clientserv,winhndl,1001,#FD_ACCEPT)=0:End:EndIf ; Get Serverevents as message 1000

clientserv is the Socketnumber of the server connected to. winhndl the WindowHandle returned by OpenWindow. 1001 is a ID you can freely set.
After an incoming network-connection (#FD_Accept) you can get an event with windowevent() and it returns 1001 to show you what happens.
Now you can filter out which server sends datas and which not.

Contact me if you need help - please sorry my lag of bad english but I hope you understand what I mean. :)

Mike

Tranquilizer/ Secretly!
Registred PureBasic User

Posted: Fri Apr 05, 2002 12:35 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

Thanks Tranquilizer/Mike!

Oh, your English was quite understandable, rather good actually, only i'm a complete lame ass when it comes to api stuff so you kind of lost me there;)
My hope was to be able to only use the native PB network functions because i wanted to make a multi OS application, with API calls and such this multi OS idea has to be dropped(i'm to lazy to do three different versions;).

I thought i drop you an email regarding your solution to this network issue. Is your email address, as stated in you profile, valid?


Frederic, are you planning on adding the functionality as requested sometime in the future. I'm not asking you to add it this instant, but sometime in the future would be nice(perhaps PB3.20 or PB3.30).

Posted: Sun Apr 07, 2002 9:41 am
by BackupUser
Restored from previous forum. Originally posted by tranquil.

At the moment it is not possible withour the using of APIs. By the way... On which way to you wait for a network event? Couse there is no WaitNetworkEvent() or something else which caches Gadget and Window events too. :P

Tranquilizer/ Secretly!
Registred PureBasic User