当前位置: 首页>>代码示例>>Java>>正文


Java Socket.send方法代码示例

本文整理汇总了Java中org.zeromq.ZMQ.Socket.send方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.send方法的具体用法?Java Socket.send怎么用?Java Socket.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.zeromq.ZMQ.Socket的用法示例。


在下文中一共展示了Socket.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendAsync

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
private static void sendAsync(int val, String account) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    Context context = ZMQ.context(1);

    //  Socket to talk to server
    Socket requester = context.socket(ZMQ.REQ);
    requester.connect("tcp://localhost:5559");
    System.out.println("launch and connect client.");
    ValidateRequest req = new ValidateRequest(account, new BigDecimal(val));

    //send request
    requester.send(objectMapper.writeValueAsString(req), 0);
    //receive response
    String responseStr = requester.recvStr(0);

    //parse and print reply
    ValidateResponse reply = objectMapper.readValue(responseStr, ValidateResponse.class);
    System.out.println("Received reply for request= " + req + " reply= " + reply + "");

    //  We never get here but clean up anyhow
    requester.close();
    context.term();
}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:24,代码来源:TestAsyncMicroServiceMain.java

示例2: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main( String[] args )
{
	final ZContext ctx = new ZContext();
	final Socket client = ctx.createSocket( ZMQ.PAIR );
	//client.connect( "ipc:///tmp/zmqtest" );
	client.connect( "tcp://localhost:5556" );
	
	String msg = "";
	for ( int i = 0; i < 10; ++i )
	{
		client.send( "Hello " + i );
	}
	
	client.send( "exit" );
	
	ctx.destroy();
}
 
开发者ID:saalfeldlab,项目名称:bigcat,代码行数:21,代码来源:ZmqTestClient.java

示例3: handShake

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public void handShake() throws Exception {
	
	context = new ZContext();
	Socket server = context.createSocket(ZMQ.REQ);
	server.connect(connectionString);
	
	server.send(request.toMsg());
	String reply = new String(server.recv());
	context.destroy();
	
	if (reply.startsWith("ERROR"))
		throw new Exception(reply);
	
	String[] parts = reply.split(" ");
	port = Integer.parseInt(parts[0]);
	recordsHint = Integer.parseInt(parts[1]);
}
 
开发者ID:enricobacis,项目名称:storm-joiner,代码行数:18,代码来源:DataServerConnector.java

示例4: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void main (String[] args) throws Exception {
    Context context = ZMQ.context (1);

    //  Socket to talk to server
    Socket responder = context.socket (ZMQ.REP);
    responder.connect ("tcp://localhost:5560");

    while (!Thread.currentThread ().isInterrupted ()) {
        //  Wait for next request from client
        String string = responder.recvStr (0);
        System.out.printf ("Received request: [%s]\n", string);

        //  Do some 'work'
        Thread.sleep (1000);

        //  Send reply back to client
        responder.send ("World");
    }

    //  We never get here but clean up anyhow
    responder.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:24,代码来源:rrworker.java

示例5: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Override
public void run()
{
    ZContext ctx = new ZContext();
    Socket client = ctx.createSocket(ZMQ.REQ);
    client.connect(String.format("ipc://%s-localfe.ipc", self));

    while (true) {
        //  Send request, get reply
        client.send("HELLO", 0);
        String reply = client.recvStr(0);
        if (reply == null)
            break;              //  Interrupted
        System.out.printf("Client: %s\n", reply);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:22,代码来源:peering2.java

示例6: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public void run() {
    ZContext ctx = new ZContext();
    Socket client = ctx.createSocket(ZMQ.DEALER);

    //  Set random identity to make tracing easier
    String identity = String.format("%04X-%04X", rand.nextInt(), rand.nextInt());
    client.setIdentity(identity.getBytes(ZMQ.CHARSET));
    client.connect("tcp://localhost:5570");

    PollItem[] items = new PollItem[] { new PollItem(client, Poller.POLLIN) };

    int requestNbr = 0;
    while (!Thread.currentThread().isInterrupted()) {
        //  Tick once per second, pulling in arriving messages
        for (int centitick = 0; centitick < 100; centitick++) {
            ZMQ.poll(items, 10);
            if (items[0].isReadable()) {
                ZMsg msg = ZMsg.recvMsg(client);
                msg.getLast().print(identity);
                msg.destroy();
            }
        }
        client.send(String.format("request #%d", ++requestNbr), 0);
    }
    ctx.destroy();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:27,代码来源:asyncsrv.java

示例7: run

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Override
public void run(Object[] args, ZContext ctx, Socket pipe)
{
    Socket publisher = ctx.createSocket(ZMQ.PUB);
    publisher.bind("tcp://*:6000");
    Random rand = new Random(System.currentTimeMillis());

    while (!Thread.currentThread().isInterrupted()) {
        String string = String.format("%c-%05d", 'A' + rand.nextInt(10), rand.nextInt(100000));
        if (!publisher.send(string))
            break;              //  Interrupted
        try {
            Thread.sleep(100);     //  Wait for 1/10th second
        } catch (InterruptedException e) {
        }
    }
    ctx.destroySocket(publisher);
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:19,代码来源:espresso.java

示例8: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * Send a string using ZMQ. The program has been originally used for sending control messages in Idommar.
 * @param args
 */
public static void main(String[] args) throws Exception {

	if ( args.length < 2 ) {
		System.out.println("missing parameters");
		return;
	}

	try {
		// read the command line arguments and create a ZMQ context.
		String address = args[0];
		String command = args[1];
		Context context = ZMQ.context(1);
		Socket controlSocket = context.socket(ZMQ.REQ);
		//System.out.println("ALGO: ZMQ created context");
		
		// configure the ZMQ connection
		controlSocket.setReceiveTimeOut(10000);
		controlSocket.connect(address);
		
		// send the command
		controlSocket.send(command);
		//System.out.println("ZMQ connected to socket");
		
		// close the socket and terminate the context.
		controlSocket.close();
		context.term();
	} catch (Exception e) {
		e.printStackTrace();
		System.exit(0);
	}
}
 
开发者ID:jasjisdo,项目名称:spark-newsreel-recommender,代码行数:36,代码来源:StringSender.java

示例9: runKernelDebug

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void runKernelDebug(Session session) throws FileNotFoundException,
        InvalidKeyException,
        UnsupportedEncodingException,
        IOException {
    Session._DEBUG_ = true;
    ZContext ctx = new ZContext();
    Socket channel = ctx.createSocket(ZMQ.REP);
    channel.bind("tcp://127.0.0.1:2222");
    byte[] msg = channel.recv();
    String sArgs = new String(msg, StandardCharsets.UTF_8);
    String[] newArgs = sArgs.split(" ");
    channel.send("ok");
    runKernel(session, newArgs);
}
 
开发者ID:fiber-space,项目名称:jupyter-kernel-jsr223,代码行数:15,代码来源:Session.java

示例10: send

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
protected void send(final Message message, final Socket zmqSocket) throws IOException
{
    message.getHeader().setSession(id);

    if (isNotBlank(userName))
    {
        message.getHeader().setUsername(userName);
    }

    final List<byte[]> frames = protocol.toFrames(message);
    final int framesSize = frames.size();

    for (int i = 0; i < framesSize; i++)
    {
        final boolean lastFrame = i == (framesSize - 1);

        final byte[] frame = frames.get(i);

        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("Sending {}frame: {}", (lastFrame ? "last " : ""), new String(frame,
                Protocol.ENCODING));
        }

        if (lastFrame)
        {
            if (!zmqSocket.send(frame))
            {
                throw new IOException("Failed to send frame " + i + " of message: " + message);
            }
        }
        else
        {
            if (!zmqSocket.sendMore(frame))
            {
                throw new IOException("Failed to send frame " + i + " of message: " + message);
            }
        }
    }
}
 
开发者ID:openanalytics,项目名称:japyter,代码行数:41,代码来源:Session.java

示例11: execute

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
@Override
public void execute(ServiceContext serviceContext) throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    Context context = ZMQ.context(1);

    //  Socket to talk to server
    Socket responder = context.socket(ZMQ.REP);
    responder.connect(zeroMqBrokerAddress);
    ZMQ.PollItem items[] = {new ZMQ.PollItem(responder, ZMQ.Poller.POLLIN)};
    while (!Thread.currentThread().isInterrupted() && !serviceContext.isCancelled()) {
        //  Wait for next request from client
        int rc = ZMQ.poll(items, 1000);
        if (rc == -1) {
            continue;
        }

        if (items[0].isReadable()) {
            String reqStr = responder.recvStr(0);
            System.out.printf("Received request: [%s]\n", reqStr);

            ValidateRequest req = objectMapper.readValue(reqStr, ValidateRequest.class);

            ValidateResponse result = validateOperation(req.getAccount(), req.getSum());
            System.out.printf("send response request: [%s]\n", result);

            responder.send(objectMapper.writeValueAsString(result));
        }
    }
    System.out.println("Stop async read!");

    //  We never get here but clean up anyhow
    responder.close();
    context.term();

}
 
开发者ID:srecon,项目名称:ignite-book-code-samples,代码行数:36,代码来源:AsyncBankServiceImpl.java

示例12: done

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public void done() {
	context = new ZContext();
	Socket server = context.createSocket(ZMQ.REQ);
	server.connect(connectionString);
	
	server.send("DONE " + port);
	server.recv();       // ACK
	context.destroy();
}
 
开发者ID:enricobacis,项目名称:storm-joiner,代码行数:10,代码来源:DataServerConnector.java

示例13: send

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
/**
 * Method to call org.zeromq.Socket send() method.
 * 
 * @param socket 0MQ socket to send on
 * @param flags Valid send() method flags, defined in org.zeromq.ZMQ class
 * @return True if success, else False
 */
public boolean send(Socket socket, int flags) {
    if (socket == null) {
        throw new IllegalArgumentException("socket parameter must be set");
    }
    if (!hasData()) {
        throw new IllegalAccessError("Cannot send frame without data");
    }

    // Note the jzmq Socket.cpp JNI class does a memcpy of the byte data before calling
    // the 0MQ send function, so don't have to clone the message data again here.
    return socket.send(data, flags);
}
 
开发者ID:zeromq,项目名称:jzmq3-x,代码行数:20,代码来源:ZFrame.java

示例14: sendSingle

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
private static void sendSingle(kvmsg msg, byte[] identity, String subtree, Socket socket)
{
    if (msg.getKey().startsWith(subtree)) {
        socket.send (identity,    //  Choose recipient
                        ZMQ.SNDMORE);
        msg.send(socket);
    }
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:9,代码来源:clonesrv6.java

示例15: main

import org.zeromq.ZMQ.Socket; //导入方法依赖的package包/类
public static void main(String[] argv) throws Exception
{
    Random rand = new Random(System.nanoTime());

    Context context = ZMQ.context(1);
    Socket server = context.socket(ZMQ.REP);
    server.bind("tcp://*:5555");

    int cycles = 0;
    while (true) {
        String request = server.recvStr();
        cycles++;

        //  Simulate various problems, after a few cycles
        if (cycles > 3 && rand.nextInt(3) == 0) {
            System.out.println("I: simulating a crash");
            break;
        } else if (cycles > 3 && rand.nextInt(3) == 0) {
            System.out.println("I: simulating CPU overload");
            Thread.sleep(2000);
        }
        System.out.printf("I: normal request (%s)\n", request);
        Thread.sleep(1000);              //  Do some heavy work
        server.send(request);
    }
    server.close();
    context.term();
}
 
开发者ID:zeromq,项目名称:jeromq3-x,代码行数:29,代码来源:lpserver.java


注:本文中的org.zeromq.ZMQ.Socket.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。