How can I accept Server Sent Event use http client using curl. #13395
-
How can I accept Server Sent Event use http client using curl. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
Please give some detail about what you are trying to do |
Beta Was this translation helpful? Give feedback.
-
You're going to have to provide more technical details. If your program
performs an HTTP request, libcurl will call the write callback repeatedly until
the entire response for that request is returned. If the program then performs
another request, then its response will be returned likewise until complete. If
the system is using something like server-side events, then the response has
unlimited length but will come in drips and drabs, with each part in a write
callback.
The diagram you show is how libcurl already works, except that the write
callback is not called on every line, but rather whenever there is data
received, no matter if it's one line, many lines, or only a part of a single
line. If the program wants it line-by-line, then it will need to include a line
parser in the write callback and buffer the responses so it can feed them
to the program line-by-line.
|
Beta Was this translation helpful? Give feedback.
-
In fact, I want to chat with openai(https://platform.openai.com/docs/api-reference/chat/create) using libcur(C++). But I don't know how to real-time accept data-only server-sent events. |
Beta Was this translation helpful? Give feedback.
curl delivers data for the protocols it supports, not raw TCP. You talk about HTTP server events here so its not really clear how getting raw TCP data would help.
If you want raw TCP, just open a socket and connect to a server.