본문 바로가기
728x90
반응형

WebSocket5

웹 소켓(WebSocket) 코드분석(server.js 편) 전체 코드 var WebSocketServer = require("ws").Server; var wss = new WebSocketServer({ port: 8001 }); CLIENTS = []; updown = []; // 연결이 수립되면 클라이언트에 메시지를 전송하고 클라이언트로부터의 메시지를 수신한다 wss.on("connection", function (ws) { //CLIENTS.push(ws); ws.on("message", function (message) { console.log("received: %s", message); var jsonData = JSON.parse(message); console.log("json=" + jsonData[0].req); if (jsonData[0]... 2022. 11. 14.
웹 소켓 (코드 분석 2 : python 편) 전체 코드 from datetime import datetime from websocket import create_connection import json ws = create_connection("ws://본인 IP:8001") min_directions): if direction == 1 and centroid[1] < count_limit: up_count += 1 trackable.counted = True cursor.execute("UPDATE dbo.TB_PASSENGER_CP set UP_CP = " + str(up_count) + " where PASSENGER_ID_CP = "+str(row3[0])) conn.commit() cursor.execute("INSERT INTO dbo... 2022. 11. 13.
웹 소켓 (코드 분석) 전체 코드 (index.jsp) var webSocket = new WebSocket("ws://192.168.110.104:8001"); webSocket.onopen = function(message) { var data = {}; var sendData = []; data['req'] = 'con'; sendData.push(data); var jsonData = JSON.stringify(sendData); webSocket.send(jsonData); }; // WebSocket 서버와 접속이 끊기면 호출되는 함수 webSocket.onclose = function(message) { }; // WebSocket 서버와 통신 중에 에러가 발생하면 요청되는 함수 webSocket.onerror =.. 2022. 11. 13.
[파이썬] 웹 소켓 사용하기!😊 1. 웹 소켓 라이브러리 설치 pip install websockets 2. 웹 소켓 스크립트 작성 # 웹 소켓 서버사용 start # # import asyncio; # 웹 소켓 모듈을 선언한다. import websockets; # 클라이언트 접속이 되면 호출된다. async def accept(websocket, path): while True: # 클라이언트로부터 메시지를 대기한다. data = await websocket.recv(); print("receive : " + data); # 클라인언트로 echo를 붙여서 재 전송한다. await websocket.send("echo : " + data); # 웹 소켓 서버 생성.호스트는 localhost에 port는 9998로 생성한다. start.. 2022. 11. 12.
728x90
반응형