Getting Started

18 views
Skip to first unread message

h.schenk

unread,
Jan 20, 2012, 8:44:52 AM1/20/12
to unitt-project
Hi,

i try to build a Java Client Websocket implemenation.
I downloaded the sl4f.jars from http://www.slf4j.org/download.html and
included the
- slf4j-api-1.6.4.jar
- slf4j-simple-1.6.4.jar
in my eclipse project to build path.
I also downloaded the apache commons codec 1.6 from
http://commons.apache.org/codec/download_codec.cgi and included
- commons-codex-1.6.jar
in my eclipse project to build path.
Also Netty from http://www.jboss.org/netty/downloads.html and included
netty-3.2.7.Final.jar and the websocket-0.9.2.1.jar from
http://code.google.com/p/unitt/downloads/list .

My Approach look like this:

MyWebSocket.java

package de.test;

import java.net.URI;
import java.util.List;

import com.unitt.framework.websocket.WebSocket;
import com.unitt.framework.websocket.WebSocketConnectConfig;
import
com.unitt.framework.websocket.WebSocketConnectConfig.WebSocketVersion;
import com.unitt.framework.websocket.WebSocketObserver;
import com.unitt.framework.websocket.netty.ClientWebsocketFactory;
import com.unitt.framework.websocket.simple.SimpleSocketFactory;

public class MyWebSocket implements WebSocketObserver {

private WebSocket ws;

@Override
public void onBinaryMessage(byte[] arg0) {
// TODO Auto-generated method stub
System.out.println("onBinaryMessage");

}

@Override
public void onClose(int arg0, String arg1, Exception arg2) {
// TODO Auto-generated method stub
System.out.println("onClose");

}

@Override
public void onError(Exception arg0) {
// TODO Auto-generated method stub
System.out.println("onError");

}

@Override
public void onOpen(String arg0, List<String> arg1) {
// TODO Auto-generated method stub
System.out.println("onOpen");

}

@Override
public void onPong(String arg0) {
// TODO Auto-generated method stub
System.out.println("onPong");

}

@Override
public void onTextMessage(String arg0) {
// TODO Auto-generated method stub
System.out.println("onTextMessage: " + arg0.toString());

}

public MyWebSocket(URI url){
WebSocketConnectConfig config = new WebSocketConnectConfig();
config.setUrl(url);
config.setWebSocketVersion(WebSocketVersion.Version08); // 10 is not
supproted by jetty
ws = SimpleSocketFactory.create(config, this);
}

public void openMysocket(){
ws.open();
}

public void sendMsg(String msg){
ws.sendMessage(msg);
}

public void closeMysocket(){
ws.close();
}



}

startClient.java:

package de.test;

import java.net.URI;
import java.net.URISyntaxException;

public class startClient {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub


try {
URI serverurl = new URI("ws://172.30.17.110:8080/WSTest/
WebServletTest");
MyWebSocket sock = new MyWebSocket(serverurl);

sock.openMysocket();

sock.sendMsg("hello world");


try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

sock.closeMysocket();


} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



}

}


I tested with Jetty and the console in eclipse shows the following:
onOpen
Closing with (0): null
Message Bytes:
Fragment:
Bytes: 88,80,f5,f4,a,2e,
onClose

I did not wrote an extra server implementation, but used the jetty
build-in implementation for websockets. I tested the jetty websocket
servlet with another websocket client using weberknecht-websockets.

Have i to use an extra implementation possibly provided by unitt-
websockets?

thank you for your help in advance
best regards
hsch



Josh Morris

unread,
Jan 30, 2012, 11:22:20 AM1/30/12
to unitt-project
Sorry for the delay in responding to you. My daughter was just born
about the time you posted your question. What version of Jetty are you
running? You might want to try setting it to rev07. They have fixed
some bugs in the Jetty server, but Jetty is what I use to test the
client. You can also look at the JUnit tests to see how I am
connecting.

Josh Morris

On Jan 20, 6:44 am, "h.schenk" <h.sch...@web.de> wrote:
> Hi,
>
> i try to build a Java Client Websocket implemenation.
> I downloaded the sl4f.jars fromhttp://www.slf4j.org/download.htmland
> included the
> - slf4j-api-1.6.4.jar
> - slf4j-simple-1.6.4.jar
> in my eclipse project to build path.
> I also downloaded the apache commons codec 1.6 fromhttp://commons.apache.org/codec/download_codec.cgiand included
> - commons-codex-1.6.jar
> in my eclipse project to build path.
> Also Netty fromhttp://www.jboss.org/netty/downloads.htmland included
Reply all
Reply to author
Forward
0 new messages