Java websocket Client

Source: Internet
Author: User

Pom.xml

<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>javanative</groupid>     <artifactId>JavaNative</artifactId>    <version> 1.0-snapshot</version>    <packaging>jar</packaging>     <name>javanative</name>    <url>http://maven.apache.org</url >    <properties>        < project.build.sourceencoding>utf-8</project.build.sourceencoding>    </ Properties>    <dependencies>        <dependency>             <groupId>org.glassfish.tyrus.bundles</groupId>             <artifactid>tyrus-standalone-client</artifactid >            <version>1.9</version>         </dependency>    </dependencies ></project>

websocket.client.simpleclient

package websocket.client;import javax.websocket.*;import java.io.ioexception;import  java.net.uri;/** * created by administrator on 2016/4/17. */@ clientendpointpublic class simpleclient {     @OnOpen      public void onopen (session session)  {         system.out.println ("open ... ");    }     @OnMessage     public void onmessage (string message)  {     &NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN (message);    }     @OnError     public void onerror (throwable t)  {         t.printstacktrace ();     }    public static  void main (String[] args) Throws exception{        websocketcontainer container =  Containerprovider.getwebsocketcontainer ();         string uri  = "Ws://localhost:8077/web/simplewebsocket";         System.out.println ("connecting to 2" + uri);         Session session = container.connecttoserver (Simpleclient.class, uri.create (URI));         session.getbasicremote (). SendText ("This is a message sent from a Java client   ... ");         thread.sleep (+);         session.close ();     }}


Java websocket Client

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.