WebSocket()
생성자는 새로운 WebSocket
객체를 반환한다.
Syntax
var ws = new WebSocket("ws://localhost:8080");
Parameters
url
- 연결할 곳의 URL; 웹소켓 서버가 응답할 수 있는 URL 값을 지정해줘야 한다.
protocols
Optional- 단일 혹은 여러개의 프로토콜 배열. 이 문자열들은 서브 프로토콜들을 가리킨다. 따라서 하나의 서버는 여러개의 서브 프로토콜을 구현할 수 있다. (예를 들면, 한 개의 서버에서
protocol
에 따라 다양한 상호 작용 방식을 사용하기를 바랄 수 있다) . 만약 프로토콜을 지정해주지 않으면, 비어 있다고 간주한다.
Exceptions thrown
SECURITY_ERR
- 연결을 시도하는 포트가 닫혀 있을 때 발생한다.
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'the WebSocket constructor' in that specification. |
Living Standard |
Browser compatibility
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.