Commit 230fdbf6 by TongZuu

..

parents
/target/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test-websocket</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.csc.test</groupId>
<artifactId>test-websocket</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.websocket</groupId>
<artifactId>jboss-websocket-api_1.0_spec</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
<version>1.13.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.csc.test;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.websocket.ClientEndpointConfig;
import javax.websocket.DeploymentException;
import org.glassfish.tyrus.client.ClientManager;
public class ClientEndpointFactory {
private static ClientEndpointFactory instance = null;
private ClientManager clientManager = ClientManager.createClient();
private ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
private ClientEndpointFactory(){
}
public static ClientEndpointFactory getInstance(){
if(instance == null){
instance = new ClientEndpointFactory();
}
return instance;
}
public void connect(EndpointBase endpoint) throws DeploymentException, IOException, URISyntaxException{
clientManager.connectToServer(endpoint , cec, new URI(endpoint.getURL()));
}
}
package com.csc.test;
import javax.websocket.Endpoint;
public abstract class EndpointBase extends Endpoint{
public String getURL(){
return WebsocketConfig.URIPATH;
}
}
package com.csc.test;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicInteger;
import javax.websocket.DeploymentException;
import javax.websocket.EndpointConfig;
import javax.websocket.MessageHandler;
import javax.websocket.PongMessage;
import javax.websocket.Session;
public class TestPingEndpoint extends EndpointBase{
private String TAGNAME = "";
private Session session;
private static AtomicInteger counter = new AtomicInteger();
public static void main(String[] arg) throws DeploymentException, IOException, URISyntaxException{
for(int i = 0; i<1000; i++){
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
new TestPingEndpoint().process();
} catch (DeploymentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
});
t.start();
}
}
public TestPingEndpoint() throws DeploymentException, IOException, URISyntaxException{
this.TAGNAME = Thread.currentThread().getName();
ClientEndpointFactory.getInstance().connect(this);
}
public void process() throws DeploymentException, IOException, URISyntaxException{
while(true){
try{
// println("ping");
session.getBasicRemote().sendPing(ByteBuffer.wrap(String.valueOf(System.currentTimeMillis()).getBytes()));
Thread.sleep(3000);
}catch(Exception e){
e.printStackTrace();
}
}
}
@Override
public void onOpen(Session session, EndpointConfig config) {
println("session.open");
this.session = session;
session.addMessageHandler(new MessageHandler.Whole<PongMessage>() {
@Override
public void onMessage(PongMessage message) {
try{
println("pong : " + counter.incrementAndGet());
String s = new String(message.getApplicationData().array());
System.out.println("Latency : "+(System.currentTimeMillis()-Long.valueOf(s)));
}catch(Exception e){
e.printStackTrace();
}
}
});
}
public void println(String message){
System.out.println(TAGNAME + " : " + message);
}
@Override
public String getURL() {
return String.format(WebsocketConfig.URIPATH_PATTERN, this.TAGNAME , System.currentTimeMillis());
}
}
package com.csc.test;
import javax.websocket.ClientEndpointConfig;
import org.glassfish.tyrus.client.ClientManager;
public class TestWebsocket {
private ClientManager clientManager = ClientManager.createClient();
private ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();
public static void main(String[] args) {
}
}
package com.csc.test;
public class WebsocketConfig {
// public static final String URIPATH_PATTERN = "ws://10.1.1.106:8080/ZeemeWebApp/CSCWS/%s/%s";
// public static final String URIPATH_PATTERN = "ws://192.168.1.131:8080/ZeemeWebApp/CSCWS/%s/%s";
// public static final String URIPATH_PATTERN = "ws://192.168.1.131:8080/ZeemeWebApp/TESTWS";
// public static final String URIPATH_PATTERN = "ws://122.155.204.120:8080/ZeemeWebApp/CSCWS/%s/%s";
public static final String URIPATH_PATTERN = "wss://zm.csc.co.th/ZeemeWebApp/CSCWS/%s/%s";
public static String URIPATH = String.format(URIPATH_PATTERN, "DV-001", "M001");
//public static String URIPATH = "ws://10.01.1.91:8080/hr/TESTWS2";
//public static String URIPATH = "ws://www.sf2online.com:8080/hr/TESTWS";
//public static String URIPATH = "ws://10.1.1.93:8330/websocket-loadbalance-1.0-SNAPSHOT/chat";
//public static String URIPATH = "ws://10.1.1.92:8330/hcloud/wscsc";
// public static Class classEndPoint = TestReceiveMessage.class;
public static int maximumClient = 1;
public static int maxThread = 10;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment