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


Java StandardWebSocketClient类代码示例

本文整理汇总了Java中org.springframework.web.socket.client.standard.StandardWebSocketClient的典型用法代码示例。如果您正苦于以下问题:Java StandardWebSocketClient类的具体用法?Java StandardWebSocketClient怎么用?Java StandardWebSocketClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: main

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
public static void main(String... argv) {
    WebSocketClient webSocketClient = new StandardWebSocketClient();
    WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());

    String url = "ws://127.0.0.1:8080/hello";
    StompSessionHandler sessionHandler = new MySessionHandler();
    stompClient.connect(url, sessionHandler);

    new Scanner(System.in).nextLine(); //Don't close immediately.
}
 
开发者ID:nielsutrecht,项目名称:spring-boot-websocket-client,代码行数:13,代码来源:ServiceClient.java

示例2: connect

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
public void connect(URI wampEndpointUrl) throws InterruptedException,
		ExecutionException, IOException, TimeoutException {
	List<WampRole> roles = new ArrayList<>();
	roles.add(new WampRole("publisher"));
	roles.add(new WampRole("subscriber"));
	roles.add(new WampRole("caller"));
	HelloMessage helloMessage = new HelloMessage("realm", roles);

	WebSocketClient webSocketClient = new StandardWebSocketClient();
	this.webSocketSession = webSocketClient
			.doHandshake(this.result, this.headers, wampEndpointUrl).get();

	sendMessage(helloMessage);
	WelcomeMessage welcomeMessage = this.result.getWelcomeMessage();
	this.result.reset();
	this.wampSessionId = welcomeMessage.getSessionId();
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:18,代码来源:WampClient.java

示例3: sendWampMessage

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
protected WampMessage sendWampMessage(WampMessage msg, DataFormat dataFormat)
		throws InterruptedException, ExecutionException, TimeoutException,
		IOException {
	CompletableFutureWebSocketHandler result = new CompletableFutureWebSocketHandler();
	WebSocketClient webSocketClient = new StandardWebSocketClient();

	try (WebSocketSession webSocketSession = webSocketClient
			.doHandshake(result, getHeaders(dataFormat), wampEndpointUrl()).get()) {

		List<WampRole> roles = new ArrayList<>();
		roles.add(new WampRole("publisher"));
		roles.add(new WampRole("subscriber"));
		roles.add(new WampRole("caller"));
		HelloMessage helloMessage = new HelloMessage("realm", roles);
		sendMessage(dataFormat, webSocketSession, helloMessage);

		result.getWelcomeMessage();

		sendMessage(dataFormat, webSocketSession, msg);

		return result.getWampMessage();
	}
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:24,代码来源:BaseWampTest.java

示例4: main

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
public static void main(String[] args) {
	DefaultSetting.setDefaultNetwork();
	if(args.length==0){
		OutputMessage.error("please enter parameter");
		return;
	}
	Map<String, String> params = parseParamsToMap(args);
	if(params==null){
		return;
	}
	// set host, port and websocket port
	DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), params.get("wsPort"));
	final String address = params.get("address");
	final String WS_URI = DefaultSetting.getWsUri();
	// create WebSocket client
	List<Transport> transports = new ArrayList<Transport>(1);
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	WebSocketClient transport = new SockJsClient(transports);
	WebSocketStompClient stompClient = new WebSocketStompClient(transport);
	stompClient.setMessageConverter(new StringMessageConverter());
	StompSessionHandler handler = new WsMonitorMultisigHandler(address);
	stompClient.connect(WS_URI, handler);
	//block and monitor exit action
	ScannerUtil.monitorExit();
}
 
开发者ID:NEMChina,项目名称:nem-apps,代码行数:26,代码来源:ImplMonitorMultisigTransaction.java

示例5: main

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
public static void main(String[] args) {
	DefaultSetting.setDefaultNetwork();
	if(args.length==0){
		OutputMessage.error("please enter parameter");
		return;
	}
	Map<String, String> params = parseParamsToMap(args);
	if(params==null){
		return;
	}
	// set host, port and websocket port
	DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), params.get("wsPort"));
	final String address = params.get("address");
	final String WS_URI = DefaultSetting.getWsUri();
	// create WebSocket client
	List<Transport> transports = new ArrayList<Transport>(1);
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	WebSocketClient transport = new SockJsClient(transports);
	WebSocketStompClient stompClient = new WebSocketStompClient(transport);
	stompClient.setMessageConverter(new StringMessageConverter());
	StompSessionHandler handler = new WsMonitorImcomingHandler(address);
	stompClient.connect(WS_URI, handler);
	//block and monitor exit action
	ScannerUtil.monitorExit();
}
 
开发者ID:NEMChina,项目名称:nem-apps,代码行数:26,代码来源:ImplMonitorIncomingTransaction.java

示例6: stompClient

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(WebSocketStompClient.class)
public WebSocketStompClient stompClient(MessageConverter messageConverter,
                                        ThreadPoolTaskScheduler taskScheduler) {
    int bufferSizeLimit = 1024 * 1024 * 8;

    StandardWebSocketClient webSocketClient = new StandardWebSocketClient();
    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(webSocketClient));
    SockJsClient sockJsClient = new SockJsClient(transports);
    WebSocketStompClient client = new WebSocketStompClient(sockJsClient);
    client.setInboundMessageSizeLimit(bufferSizeLimit);
    client.setMessageConverter(messageConverter);
    client.setTaskScheduler(taskScheduler);
    client.setDefaultHeartbeat(new long[]{0, 0});
    return client;
}
 
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:18,代码来源:ZuulWebSocketConfiguration.java

示例7: main

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    WebSocketClient client = new StandardWebSocketClient();
    String url = "ws://localhost:8081/socket";
    ListenableFuture<WebSocketSession> future = client.doHandshake(new AbstractWebSocketHandler() {
        @Override
        public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
            System.out.println(message.getPayload());
        }
    }, url);

    WebSocketSession socketSession = future.get();
    socketSession.sendMessage(new TextMessage("{\"command\":\"test\",\"parameters\":{\"type\":\"conn\"}}"));

    System.in.read();
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:16,代码来源:WebSocketClientTests.java

示例8: setUp

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

	logger.debug("Setting up before '" + this.testName.getMethodName() + "'");

	this.wac = new AnnotationConfigWebApplicationContext();
	this.wac.register(TestConfig.class);
	this.wac.refresh();

	this.server = new TomcatWebSocketTestServer();
	this.server.setup();
	this.server.deployConfig(this.wac);
	this.server.start();

	WebSocketClient webSocketClient = new StandardWebSocketClient();
	this.stompClient = new WebSocketStompClient(webSocketClient);
	this.stompClient.setMessageConverter(new StringMessageConverter());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:WebSocketStompClientIntegrationTests.java

示例9: setup

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
	log.info("Setting up Quotes Web Socket Integration test....");
	port = SocketUtils.findAvailableTcpPort();

	server = new TomcatWebSocketTestServer(port);
	server.deployConfig(FrontendWebApplicationInitializer.class);
	server.start();

	loginAndSaveXAuthToken("harrymitchell", "HarryMitchell5!", headers);

	List<Transport> transports = new ArrayList<>();
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	RestTemplateXhrTransport xhrTransport = new RestTemplateXhrTransport(new RestTemplate());
	xhrTransport.setRequestHeaders(headers);
	transports.add(xhrTransport);

	sockJsClient = new SockJsClient(transports);
       sockJsClient.setHttpHeaderNames("X-Auth-Token");
	log.info("Setup complete!");
}
 
开发者ID:bjornharvold,项目名称:bearchoke,代码行数:22,代码来源:QuotesWebSocketIntegrationTest.java

示例10: setup

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
@Before
public void setup() {
    List<Transport> transports = new ArrayList<>();
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    this.sockJsClient = new SockJsClient(transports);

    this.stompClient = new WebSocketStompClient(sockJsClient);
    this.stompClient.setMessageConverter(new MappingJackson2MessageConverter());
}
 
开发者ID:sweetca,项目名称:logger,代码行数:10,代码来源:LogIntegrationTests.java

示例11: main

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
public static void main(String args[]) throws Exception
   {
WebSocketClient simpleWebSocketClient =
    new StandardWebSocketClient();
List<Transport> transports = new ArrayList<>(1);
transports.add(new WebSocketTransport(simpleWebSocketClient));

SockJsClient sockJsClient = new SockJsClient(transports);
WebSocketStompClient stompClient =
    new WebSocketStompClient(sockJsClient);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());

String url = "ws://localhost:9090/chat";
String userId = "spring-" +
    ThreadLocalRandom.current().nextInt(1, 99);
StompSessionHandler sessionHandler = new MyStompSessionHandler(userId);
StompSession session = stompClient.connect(url, sessionHandler)
    .get();
BufferedReader in =
    new BufferedReader(new InputStreamReader(System.in));
for (;;) {
    System.out.print(userId + " >> ");
    System.out.flush();
    String line = in.readLine();
    if ( line == null ) break;
    if ( line.length() == 0 ) continue;
    ClientMessage msg = new ClientMessage(userId, line);
    session.send("/app/chat/java", msg);
}
   }
 
开发者ID:jaysridhar,项目名称:spring-websocket-client,代码行数:31,代码来源:Application.java

示例12: setup

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
@Before
public void setup() {
	List<Transport> transports = new ArrayList<>();
	transports.add(new WebSocketTransport(new StandardWebSocketClient()));
	this.sockJsClient = new SockJsClient(transports);

	this.stompClient = new WebSocketStompClient(sockJsClient);
	this.stompClient.setMessageConverter(new MappingJackson2MessageConverter());
}
 
开发者ID:WASdev,项目名称:sample.SpringBootWebsocket,代码行数:10,代码来源:GreetingIntegrationTestIT.java

示例13: process

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
@Override
public void process() {

    BlockchainWebSocketHandler handler = new BlockchainWebSocketHandler();
    WebSocketClient client = new StandardWebSocketClient();
    try {
        WebSocketSession session = client.doHandshake(handler, WS_URI).get();
        session.sendMessage(new TextMessage("Hello World test."));
        session.close();
    } catch (Exception e) {
        logger.info(e);
    }
}
 
开发者ID:DanielJyc,项目名称:simpleblockchain,代码行数:14,代码来源:SendMessageClientImpl.java

示例14: createWebSocketClientSession

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
private WebSocketSession createWebSocketClientSession(WebSocketSession webSocketServerSession) {
    try {
        return new StandardWebSocketClient()
                .doHandshake(new WebSocketProxyClientHandler(webSocketServerSession), "ws://localhost:9999")
                .get(1000, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:barrett-rob,项目名称:java-websocket-reverse-proxy,代码行数:10,代码来源:NextHop.java

示例15: run

import org.springframework.web.socket.client.standard.StandardWebSocketClient; //导入依赖的package包/类
@Test
public void run() throws Exception {
    List<Transport> transports = new ArrayList<Transport>(2);
    transports.add(new WebSocketTransport(new StandardWebSocketClient()));
    transports.add(new RestTemplateXhrTransport());

    SockJsClient sockJsClient = new SockJsClient(transports);
    ListenableFuture<WebSocketSession> wsSession = sockJsClient.doHandshake(
        this.webSocketHandler, "ws://localhost:" + this.port + "/sockjs");

    this.thrown.expect(ExecutionException.class);
    wsSession.get().sendMessage(new TextMessage("a"));
}
 
开发者ID:xianrendzw,项目名称:CodeMaster,代码行数:14,代码来源:ApplicationTests.java


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