JNIEXPORT jlong JNICALL Java_org_zeromq_czmq_Zsock__1_1newStream (JNIEnv *env, jclass c, jstring endpoint) { char *endpoint_ = (char *) (*env)->GetStringUTFChars (env, endpoint, NULL); jlong new_stream_ = (jlong) (intptr_t) zsock_new_stream (endpoint_); (*env)->ReleaseStringUTFChars (env, endpoint, endpoint_); return new_stream_; }
void zhttp_client_test (bool verbose) { #if defined(HAVE_LIBCURL) && defined(ZMQ_STREAM) printf (" * zhttp_client: "); zsock_t *server = zsock_new_stream (NULL); int port = zsock_bind (server, "tcp://127.0.0.1:*"); char url[255]; sprintf (url, "http://127.0.0.1:%d", port); // @selftest // Simple create/destroy test zhttp_client_t *self = zhttp_client_new (verbose); assert (self); // Send the get request zlistx_t *headers = zlistx_new (); zlistx_add_end (headers, "Host: zeromq.org"); zhttp_client_get (self, url, headers, NULL); zlistx_destroy (&headers); // Receive request on the server zchunk_t *routing_id; char *request; int rc = zsock_recv (server, "cs", &routing_id, &request); assert (rc == 0); // Send the response char* response = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nHello"; zsock_send (server, "cs", routing_id, response); // Receive the response on the http client int code; zchunk_t *data; zhttp_client_recv (self, &code, &data, NULL); assert (zchunk_streq (data, "Hello")); // Sending another request, without being answer // Checking the client ability to stop while request are inprogres zhttp_client_get (self, url, NULL, NULL); zchunk_destroy (&data); zchunk_destroy (&routing_id); zstr_free (&request); zhttp_client_destroy (&self); zsock_destroy (&server); // @end printf ("OK\n"); #endif }
/// // Create a STREAM socket. Default action is connect. QZsock* QZsock::newStream (const QString &endpoint, QObject *qObjParent) { return new QZsock (zsock_new_stream (endpoint.toUtf8().data()), qObjParent); }
Z K1(zsocknewstream){R ptr(zsock_new_stream(xs));}
/// // Create a STREAM socket. Default action is connect. QmlZsock *QmlZsockAttached::constructStream (const QString &endpoint) { QmlZsock *qmlSelf = new QmlZsock (); qmlSelf->self = zsock_new_stream (endpoint.toUtf8().data()); return qmlSelf; };
void zhttp_client_test (bool verbose) { #if defined(HAVE_LIBCURL) && defined(ZMQ_STREAM) printf (" * zhttp_client: "); zsock_t *server = zsock_new_stream (NULL); int port = zsock_bind (server, "tcp://127.0.0.1:*"); char url[255]; sprintf (url, "http://127.0.0.1:%d", port); // @selftest // Simple create/destroy test zhttp_client_t *self = zhttp_client_new (verbose); assert (self); // Send the get request bool event = false; zlistx_t *headers = zlistx_new (); zlistx_add_end (headers, "Host: zeromq.org"); zhttp_client_get (self, url, headers, -1, test_handler, &event); zlistx_destroy (&headers); // Receive request on the server zchunk_t *routing_id = recv_http_request (server); // Send the response char* response = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nHello"; zsock_send (server, "cs", routing_id, response); zchunk_destroy (&routing_id); // Receive the response on the http client int rc = zhttp_client_wait (self, -1); assert (rc == 0); zhttp_client_execute (self); assert (event); // Send a POST request event = false; zchunk_t *body = zchunk_new ("World", 5); zhttp_client_post (self, url, NULL, body, -1, test_handler, &event); // Receive request on the server routing_id = recv_http_request (server); // Send the response zsock_send (server, "cs", routing_id, response); zchunk_destroy (&routing_id); // Receive the response on the http client rc = zhttp_client_wait (self, -1); assert (rc == 0); zhttp_client_execute (self); assert (event); // Timeout check event = false; zhttp_client_get (self, url, NULL, 1000, test_handler, &event); rc = zhttp_client_wait (self, 1200); assert (rc == 0); zhttp_client_execute (self); assert (event); // Sending another request, without being answer // Checking the client ability to stop while request are inprogres zhttp_client_get (self, url, NULL, -1, test_handler, NULL); zchunk_destroy (&body); zhttp_client_destroy (&self); zsock_destroy (&server); // @end printf ("OK\n"); #endif }
/// // Create a STREAM socket. Default action is connect. QmlZsock *QmlZsockAttached::newStream (const QString &endpoint) { QmlZsock *retQ_ = new QmlZsock (); retQ_->self = zsock_new_stream (endpoint.toUtf8().data()); return retQ_; };