aboutgugl.blogg.se

Purebasic select case
Purebasic select case













purebasic select case

The socket component is not "HTTP aware", meaning that it is not parsing the HTTP response and therefore does not know when it has received the full response. Some web servers close the connections quickly while others do not. The reason we do this is because different web servers will behave differently w.r.t. We'll use the StartTiming method and ElapsedSeconds property to wait a maximum of 10 seconds. We now want to write a loop that waits for data to arrive from any of the 5 connections, reads incoming data, and saves the data to files. Each of the web servers have received a GET request and will be sending a response. ProcedureReturn EndIf Next At this point we have 5 TCP/IP connections contained within the socketSet object. The only reason it might is if we try to give it an unconnected socket - but we already know it's connected at this point.ĭebug CkSocket:: ckLastErrorText(socketSet) If success 1 The TakeSocket method shouldn't fail. Success = CkSocket:: ckTakeSocket(socketSet,sock) This adds the connection to the internal set of sockets contained within socketSet. ProcedureReturn EndIf Tell the socketSet object to take ownership of the connected socket. Success = CkSocket:: ckSendString(sock,getReq) Send the HTTP GET request to the web server. GetReq = CkSocket:: ckBuildHttpGetRequest(sock, CkStringArray:: ckGetString(saUrls,i)) Build the HTTP GET request to be sent to the web server. Display the remote IP address of the connected socket:ĭebug "connected to " + CkSocket:: ckRemoteIpAddress(sock) CkSocket:: setCkUserData(sock, CkStringArray:: ckGetString(saFilenames,i)) We'll use this later when saving the data read in the HTTP response. ProcedureReturn EndIf Save a filename in the socket object's UserData. Success = CkSocket:: ckConnect(sock,domain,port,useSsl,maxWaitMs) First, connect to each of the web servers:ĭomain = CkStringArray:: ckGetString(saDomains,i) We're only communicating with HTTP servers here as a convenient way of demonstrating the technique of waiting for data to arrive from a set of connected sockets. NOTE: As you'll see later, communicating with HTTP servers is better left to the Chilkat HTTP component/library because of many HTTP protocol issues such as redirects, GZIP responses, chunked responses, etc. It will call the SelectForReading method to wait until data arrives from any of the connected sockets. NumConnections.i = 5 This example will connect to 5 different web servers, send an HTTP request to each, and read the HTTP response form each.

purebasic select case

SaFilenames.i = CkStringArray:: ckCreate()ĬkStringArray:: ckAppend(saDomains, "CkStringArray:: ckAppend(saDomains, "CkStringArray:: ckAppend(saDomains, "CkStringArray:: ckAppend(saDomains, "CkStringArray:: ckAppend(saDomains, "CkStringArray:: ckAppend(saUrls, "")ĬkStringArray:: ckAppend(saFilenames, "chilkatsoft.out")ĬkStringArray:: ckAppend(saFilenames, "cknotes.out")ĬkStringArray:: ckAppend(saFilenames, "google.out")ĬkStringArray:: ckAppend(saFilenames, "example-code.out")ĬkStringArray:: ckAppend(saFilenames, "yahoo.out") Before we begin, create a few StringArray objects holding domain names, URLs, and output filenames to be used in this example. This will be the socket object that will contain other connected sockets. See Global Unlock Sample for sample code. This example requires the Chilkat API to have been previously unlocked. The SelectForReading method waits until one or more sockets in the set have incoming data ready and available to read. Demonstrates how the Chilkat socket object can become a "socket set" that contains other connected socket objects, and this can be used to "select" on multiple sockets for reading.















Purebasic select case