Click here to Skip to main content
14,239,724 members
   

Java

 
AnswerRe: Servlet purpose Pin
Richard MacCutchan10-Jan-19 23:17
protectorRichard MacCutchan10-Jan-19 23:17 
GeneralRe: Servlet purpose Pin
Valentinor11-Jan-19 0:16
memberValentinor11-Jan-19 0:16 
GeneralRe: Servlet purpose Pin
Richard MacCutchan11-Jan-19 0:55
protectorRichard MacCutchan11-Jan-19 0:55 
AnswerRe: Servlet purpose Pin
markkuk15-Jan-19 23:51
membermarkkuk15-Jan-19 23:51 
QuestionJavaScript Syntax Pin
Bram van Kampen10-Jan-19 14:06
memberBram van Kampen10-Jan-19 14:06 
AnswerRe: JavaScript Syntax Pin
Richard MacCutchan10-Jan-19 21:55
protectorRichard MacCutchan10-Jan-19 21:55 
AnswerRe: JavaScript Syntax Pin
CHill6010-Jan-19 22:19
protectorCHill6010-Jan-19 22:19 
QuestionConnection between client and server Through websocket and vertx api Pin
Mr_z7-Jan-19 4:31
memberMr_z7-Jan-19 4:31 
 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:

<!doctype html>

<html>
    <head>
        <meta charset = "utf-8">
        <title> Wiki Project </title>
        <script type = "text/javascript">
            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@");
            }   
        </script>
    </head>
  
    <body> 
        <form name = "directing" method = "post" action = "javascript:;"> 
          Write a message: 
          <input type = "text" name = "message" size = "50" maxlength = "50" />
          <input type = "button" name = "add_message" value = "Add to server" onclick = "insertMessage()" />
          <input type = "button" name = "view_messages" value = "view messages from server" onclick = "viewMessages()" />
          <input type = "button" name = "delete_message" value = "delete message from server" onclick = "deleteMessage()" />          
        </form>   
    </body>
</html>


Java:
package com.mycompany.wiki_project;

import io.vertx.core.Vertx;

class VertxServer
{            
    private static int    place;
    private static String store_in_server[];
    private static String message_from_client;
    
    public static void main(String args[])
    {   
        place = 0;
        store_in_server = new String[50];
        
        Vertx vertx = Vertx.vertx();
                
        vertx.createHttpServer()
             .websocketHandler(ws -> ws.handler(ws::writeBinaryMessage))
             .requestHandler(req ->
             {
                 req.handler(buffer -> 
                 {
                    message_from_client = buffer.getString(0, buffer.length());
                    
                    switch (message_from_client)
                    {
                        case "@View@":
                            for (int i=0; i < place; i++)
                                req.response().write(store_in_server[i]);
                            break;
                        
                        case "@Delete@":
                            place--;
                            break;
                        
                        default:
                            store_in_server[place] = message_from_client + "\n";
                            place++;
                            break;
                    }  
    
                  });          
             }).listen(8090);
    }
}

AnswerRe: Connection between client and server Through websocket and vertx api Pin
Richard MacCutchan7-Jan-19 5:29
protectorRichard MacCutchan7-Jan-19 5:29 
GeneralRe: Connection between client and server Through websocket and vertx api Pin
Mr_z7-Jan-19 5:35
memberMr_z7-Jan-19 5:35 
GeneralRe: Connection between client and server Through websocket and vertx api Pin
Richard MacCutchan7-Jan-19 6:11
protectorRichard MacCutchan7-Jan-19 6:11 
GeneralRe: Connection between client and server Through websocket and vertx api Pin
Mr_z7-Jan-19 6:31
memberMr_z7-Jan-19 6:31 
GeneralRe: Connection between client and server Through websocket and vertx api Pin
Richard MacCutchan7-Jan-19 6:38
protectorRichard MacCutchan7-Jan-19 6:38 
QuestionServlet page redirecting Pin
Valentinor4-Jan-19 21:22
memberValentinor4-Jan-19 21:22 
AnswerRe: Servlet page redirecting Pin
jschell5-Jan-19 6:39
memberjschell5-Jan-19 6:39 
GeneralRe: Servlet page redirecting Pin
Valentinor10-Jan-19 22:55
memberValentinor10-Jan-19 22:55 
QuestionCode to Read Raw data from Wireless Modem in java Pin
Member 1409909024-Dec-18 0:53
memberMember 1409909024-Dec-18 0:53 
AnswerRe: Code to Read Raw data from Wireless Modem in java Pin
Richard MacCutchan24-Dec-18 0:58
protectorRichard MacCutchan24-Dec-18 0:58 
GeneralRe: Code to Read Raw data from Wireless Modem in java Pin
Member 1409909024-Dec-18 1:03
memberMember 1409909024-Dec-18 1:03 
GeneralRe: Code to Read Raw data from Wireless Modem in java Pin
Richard MacCutchan24-Dec-18 1:04
protectorRichard MacCutchan24-Dec-18 1:04 
GeneralRe: Code to Read Raw data from Wireless Modem in java Pin
Member 1409909026-Dec-18 0:48
memberMember 1409909026-Dec-18 0:48 
GeneralRe: Code to Read Raw data from Wireless Modem in java Pin
Richard MacCutchan26-Dec-18 2:10
protectorRichard MacCutchan26-Dec-18 2:10 
AnswerRe: Code to Read Raw data from Wireless Modem in java Pin
jschell27-Dec-18 13:27
memberjschell27-Dec-18 13:27 
QuestionJava Panel Program Pin
Member 1408268117-Dec-18 11:36
memberMember 1408268117-Dec-18 11:36 
AnswerRe: Java Panel Program Pin
Richard MacCutchan17-Dec-18 22:33
protectorRichard MacCutchan17-Dec-18 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.