websocket 테스트시 eclipse오류 발생.

akayong의 이미지

환경 : win7 32bit
jdk : 1.8.0
tomcat : 7.0.72
IDE : eclipse

웹소켓이라는것을 처음 접해봅니다.
사실 자바도 거의 처음입니다.. 계속 C랑 C++만 하다가..이번에 맡게된 프로그램이 자바로 되어 있어..후..

무튼...
웹소켓이 어떻게 돌아가느냐.. 기본적인걸 좀 보기 위해 아주아주 심플한 예제를 하나 돌려보았습니다.

http://nowonbun.tistory.com/285

위의 블로그의 내용을 참조 하였고
있는 그대로 가져다 썼습니다.

WebSocket.java

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.ServerEndpoint;
 
@ServerEndpoint("/WebSocket")
public class WebSocket {
 
    @OnOpen
    public void handleOpen() {
        System.out.println("Client is connected.");
    }
 
    @OnMessage
    public String handleMessage(String message) {
        System.out.println("Receive from Client : " + message);
        String replyMessage = "echo : " + message;
        System.out.println("Send to Client : " + replyMessage);
        return replyMessage;
    }
 
    @OnClose
    public void handleClose() {
        System.out.println("Client is disconnected");
    }
 
    @OnError
    public void handleError(Throwable t) {
        t.printStackTrace();
    }
}

websocket.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Insert title here </title>
</head>
<body>
    <form>
        <input id="textMessage" type="text">
        <input onclick="sendMessage()" value="Send" type="button">
        <input onclick="disconnect()" value="Disconnect" type="button">
    </form>
    <br/>
 
    <textarea id="messageTextArea" rows="10" cols="50"></textarea>
 
    <script type="text/javascript">
        var webSocket = new WebSocket("ws://localhost:8080/websockettest/WebSocket");
        var messageTextArea = document.getElementById("messageTextArea");
 
        webSocket.onopen = function(message) {
            messageTextArea.value += "Server connect...\n";
        };
 
        webSocket.onclose = function(message) {
            messageTextArea.value += "Server disconnect...\n";
        };
 
        webSocket.onmessage = function(message) {
            messageTextArea.value += "Receive from server = " + message.data + "\n";
        };
 
        function sendMessage() {
            var message = document.getElementById("textMessage");
            messageTextArea.value += "Send to Server = " + message.value + "\n";
            webSocket.send(message.value);
            message.value="";
        }
 
        function disconnect() {
            webSocket.close();
        }
    </script>
</body>
</html>

위 2가지 파일이 다 입니다.
(테스트용 PC랑 현재 이 포스트를 작성하는 PC가 망이분리 되있어
ctrl c / ctrl v 가 되지 않아 코드를 일일이 새로 손으로 친거라 약간의 오타가 있을 수 도 있습니다.)

그리고 실제로 구동 해 보면
서버에서 잘 돌아간 후

브라우저를 통해 http://localhost:8080/websockettest/websocket.jsp 를 접속 하면
(프로젝트 명이 websockettest 입니다)

org.apache.coyote.http11.Abstracthttp11Processor process
정보 : Error parsing HTTP request header

라는 에러가 나오며

조금 밑에

java.lang.ArrayIndexOutOfBoundsException 도 발생 합니다.

일단, 저 위 코드에 Array는 없고, 내부적으로 다른 곳에서 사용 되는거 같은데
org.apache.coyote.http11.InternalInputBuffer.parseReqestLine(InternalInputBuffer.java:134)
해당 java 파일의 소스가 없고.. class만 있어서 추적도 못하겠구요..

무튼.. 저 위의 에러 원인이 뭘까요?

구글링 해서
server.xml 부분에 뭘 주석 처리 해라
maxHttpHeaderSize 를 지정해줘라
접속 포트를 바꿔줘라
등을 해 보았지만 계속 같은 증상입니다.

오늘 오후시간 내내 계속 여기서 막혀 있습니다 ㅠㅠ

이에 의심가는 부분이 있으시거나
문제를 아시는 분은 답변 부탁 드리겠습니다.

감사합니다.

akayong의 이미지

해결 했습니다. 브라우저 문제였네요..
사파리랑 파폭에선 저런 에러 나고, 크롬에선 되고..
웹소켓 지원하는 브라우저 ( http://caniuse.com/#search=websocket )
에서만 테스트 했는데도.. 브라우저 차이가 있네요..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.