Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Connection between client and server Through websocket and vertx api

Connection between client and server Through websocket and vertx api

Scheduled Pinned Locked Moved Java
questionjavajavascriptasp-netcom
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr_z
    wrote on last edited by
    #1

    Hi, I have two files one - client side in Java script, the other in Java - server side ..
    I can not send and receive messages What is the problem? Thanks

    Js:

        Wiki Project 
        window.addEventListener("load", onLoad, false);
           
            function onLoad()
            {
                var ws\_address = "ws://0.0.0.0:8090"; 
                var socket = new WebSocket(ws\_address);
                                
                socket.onopen = function(event) {onOpen(event);};
                socket.onclose = function(event) {onClose(event);};
                socket.onmessage = function(event) {onMessage(event);};
            }
            
            function onOpen(event)
            {
                alert("OPEN Connection");
            }   
            
            function onClose(event)
            {
                alert("CLOSE Connection");
            }
            
            function onMessage(event)
            {     
                alert(event.data.toString()); 
            }      
            
            function insertMessage()
            {      
                socket.send(document.directing.message.value);
                document.directing.message.value = "";
            }      
            
            function viewMessages()
            {            
                socket.send("@View@");  
            }         
    
            function deleteMessage()
            {         
                socket.send("@Delete@");
            }   
        
    
    
     
        
    
    
          Write a message: 
    

    Java:

    package com.mycompany.wiki_project;

    import io.vertx.core.Vertx;

    class VertxServer
    {
    private static int place;
    private static String store_in_server[];
    pri

    L 1 Reply Last reply
    0
    • M Mr_z

      Hi, I have two files one - client side in Java script, the other in Java - server side ..
      I can not send and receive messages What is the problem? Thanks

      Js:

          Wiki Project 
          window.addEventListener("load", onLoad, false);
             
              function onLoad()
              {
                  var ws\_address = "ws://0.0.0.0:8090"; 
                  var socket = new WebSocket(ws\_address);
                                  
                  socket.onopen = function(event) {onOpen(event);};
                  socket.onclose = function(event) {onClose(event);};
                  socket.onmessage = function(event) {onMessage(event);};
              }
              
              function onOpen(event)
              {
                  alert("OPEN Connection");
              }   
              
              function onClose(event)
              {
                  alert("CLOSE Connection");
              }
              
              function onMessage(event)
              {     
                  alert(event.data.toString()); 
              }      
              
              function insertMessage()
              {      
                  socket.send(document.directing.message.value);
                  document.directing.message.value = "";
              }      
              
              function viewMessages()
              {            
                  socket.send("@View@");  
              }         
      
              function deleteMessage()
              {         
                  socket.send("@Delete@");
              }   
          
      
      
       
          
      
      
            Write a message: 
      

      Java:

      package com.mycompany.wiki_project;

      import io.vertx.core.Vertx;

      class VertxServer
      {
      private static int place;
      private static String store_in_server[];
      pri

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You are trying to send to an invalid address.

      M 1 Reply Last reply
      0
      • L Lost User

        You are trying to send to an invalid address.

        M Offline
        M Offline
        Mr_z
        wrote on last edited by
        #3

        How do I write this?
        I need them both to listen to Port 8090

        L 1 Reply Last reply
        0
        • M Mr_z

          How do I write this?
          I need them both to listen to Port 8090

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          The port number is fine, but you are using the IP address 0.0.0.0.

          M 1 Reply Last reply
          0
          • L Lost User

            The port number is fine, but you are using the IP address 0.0.0.0.

            M Offline
            M Offline
            Mr_z
            wrote on last edited by
            #5

            i use

            var ws_address = "ws://" + document.location.host + document.location.pathname + ":8089";

            not work

            L 1 Reply Last reply
            0
            • M Mr_z

              i use

              var ws_address = "ws://" + document.location.host + document.location.pathname + ":8089";

              not work

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Try connecting to the server code through a browser to see if it will accept a normal request. I do not know Vertx so you may need to use their support lines for help.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups