<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UnityRestServer Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<atom:link href="https://lycos7560.com/category/unity/unityrestserver/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>생각의 흐름을 타고 다니며 만드는 블로그</description>
	<lastBuildDate>Fri, 09 Dec 2022 20:11:13 +0000</lastBuildDate>
	<language>ko-KR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://lycos7560.com/wp-content/uploads/2022/11/cropped-cropped-cropped-log-1-150x150-1-80x80.png</url>
	<title>UnityRestServer Archives - 어제와 내일의 나 그 사이의 이야기</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>RestServer + Unity DB연동</title>
		<link>https://lycos7560.com/unity/restserver-unity-db%ec%97%b0%eb%8f%99/832/</link>
					<comments>https://lycos7560.com/unity/restserver-unity-db%ec%97%b0%eb%8f%99/832/#respond</comments>
		
		<dc:creator><![CDATA[lycos7560]]></dc:creator>
		<pubDate>Sat, 12 Nov 2022 17:31:46 +0000</pubDate>
				<category><![CDATA[Unity]]></category>
		<category><![CDATA[UnityRestServer]]></category>
		<category><![CDATA[DB]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mysql2]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[Packets]]></category>
		<category><![CDATA[postman]]></category>
		<category><![CDATA[RestServer]]></category>
		<guid isPermaLink="false">https://lycos7560.synology.me/?p=832</guid>

					<description><![CDATA[<p>Version : Unity 2021.3.5f1 MDN The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps. 웹 사이트와 프로그레시브 웹 앱 모두에 대한 HTML, CSS 및 API를 포함한 개방형 웹 기술에 대한 정보를 제공하는 사이트 https://developer.mozilla.org/ko/docs/Web/JavaScript EXPRESS https://ninjaggobugi.tistory.com/9 &#60;- 자세한 설명 Express란?&#160; [&#8230;]</p>
<p>The post <a href="https://lycos7560.com/unity/restserver-unity-db%ec%97%b0%eb%8f%99/832/">RestServer + Unity DB연동</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<!-- HorizontalAD -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="6908948342"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Version : Unity 2021.3.5f1<strong> </strong></h2>



<h2 class="wp-block-heading"><strong>MDN</strong></h2>



<p class="has-medium-font-size">The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.<br><br>웹 사이트와 프로그레시브 웹 앱 모두에 대한 HTML, CSS 및 API를 포함한 개방형 웹 기술에 대한 정보를 제공하는 사이트<br></p>



<p><a href="https://developer.mozilla.org/ko/docs/Web/JavaScript" target="_blank" rel="noreferrer noopener">https://developer.mozilla.org/ko/docs/Web/JavaScript</a></p>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="1777" height="1006" src="https://lycos7560.com/wp-content/uploads/image-135.png" alt="" class="wp-image-2433" srcset="https://lycos7560.com/wp-content/uploads/image-135.png 1777w, https://lycos7560.com/wp-content/uploads/image-135-300x170.png 300w, https://lycos7560.com/wp-content/uploads/image-135-768x435.png 768w, https://lycos7560.com/wp-content/uploads/image-135-1536x870.png 1536w" sizes="(max-width: 1777px) 100vw, 1777px" /></figure>



<div style="height:54px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>EXPRESS</strong></h2>



<p><a rel="noreferrer noopener" href="https://ninjaggobugi.tistory.com/9" target="_blank">https://ninjaggobugi.tistory.com/9</a>    &lt;- 자세한 설명</p>



<p><em>Express</em>란?&nbsp;<br><br><em>Express</em>는 웹 및 모바일 애플리케이션을 위한 일련의 강력한 기능을 제공하는 간결하고 유연한&nbsp;<em>Node</em>.<em>js</em>&nbsp;웹 애플리케이션 프레임 워크<br><br>Node.js는&nbsp;Chrome의 V8엔진을 이용하여&nbsp;javascript로 브라우저가 아니라 서버를 구축하고, 서버에서 JavaScript가 작동되도록 해주는 런타임 환경(플랫폼)<br><br>Express는 이런 Nodejs의 원칙과 방법을 이용하여 웹애플리케이션을 만들기 위한 프레임워크이다.<br></p>



<p><a href="https://expressjs.com/ko/" target="_blank" rel="noreferrer noopener">https://expressjs.com/ko/</a></p>



<figure class="wp-block-image size-full"><img decoding="async" width="1438" height="693" src="https://lycos7560.com/wp-content/uploads/image-137.png" alt="" class="wp-image-2435" srcset="https://lycos7560.com/wp-content/uploads/image-137.png 1438w, https://lycos7560.com/wp-content/uploads/image-137-300x145.png 300w, https://lycos7560.com/wp-content/uploads/image-137-768x370.png 768w" sizes="(max-width: 1438px) 100vw, 1438px" /></figure>



<div style="height:126px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>NPM</strong></h2>



<p>npm(node package manager)은 자바스크립트 패키지 매니저이다. Node.js에서 사용할 수 있는 모듈들을 패키지화하여 모아둔 저장소 역할과 패키지 설치 및 관리를 위한 CLI(Command line interface)를 제공한다. <br><br>자신이 작성한 패키지를 공개할 수도 있고 필요한 패키지를 검색하여 재사용할 수도 있다.</p>



<p><a href="https://www.npmjs.com/">https://www.npmjs.com/</a></p>



<figure class="wp-block-image size-full"><img decoding="async" width="1344" height="697" src="https://lycos7560.com/wp-content/uploads/image-138.png" alt="" class="wp-image-2436" srcset="https://lycos7560.com/wp-content/uploads/image-138.png 1344w, https://lycos7560.com/wp-content/uploads/image-138-300x156.png 300w, https://lycos7560.com/wp-content/uploads/image-138-768x398.png 768w" sizes="(max-width: 1344px) 100vw, 1344px" /></figure>



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">Mysql</h2>



<p>Mysql용 node.js 드라이버</p>



<p><a href="https://www.npmjs.com/package/mysql" target="_blank" rel="noreferrer noopener">https://www.npmjs.com/package/mysql</a></p>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1454" height="776" src="https://lycos7560.com/wp-content/uploads/image-139.png" alt="" class="wp-image-2437" srcset="https://lycos7560.com/wp-content/uploads/image-139.png 1454w, https://lycos7560.com/wp-content/uploads/image-139-300x160.png 300w, https://lycos7560.com/wp-content/uploads/image-139-768x410.png 768w" sizes="(max-width: 1454px) 100vw, 1454px" /></figure>



<div style="height:56px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"> Mysql2</h2>



<p class="has-medium-font-size">async/await을 사용하기 위해선 mysql2를 설치 해야 한다.<br><br>콜백 방식이 싫다면 사용하자</p>



<div style="height:12px" aria-hidden="true" class="wp-block-spacer"></div>



<p><a href="https://www.npmjs.com/package/mysql2" target="_blank" rel="noreferrer noopener">https://www.npmjs.com/package/mysql2</a></p>



<figure class="wp-block-image size-full"><img decoding="async" width="1479" height="706" src="https://lycos7560.com/wp-content/uploads/image-140.png" alt="" class="wp-image-2438" srcset="https://lycos7560.com/wp-content/uploads/image-140.png 1479w, https://lycos7560.com/wp-content/uploads/image-140-300x143.png 300w, https://lycos7560.com/wp-content/uploads/image-140-768x367.png 768w" sizes="(max-width: 1479px) 100vw, 1479px" /></figure>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:42px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size">npm init 해주기</p>



<p><a href="https://www.dailysmarty.com/posts/npm-init-y-explanation" target="_blank" rel="noreferrer noopener">https://www.dailysmarty.com/posts/npm-init-y-explanation</a></p>



<div style="height:19px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1389" height="456" src="https://lycos7560.com/wp-content/uploads/image-141.png" alt="" class="wp-image-2439" srcset="https://lycos7560.com/wp-content/uploads/image-141.png 1389w, https://lycos7560.com/wp-content/uploads/image-141-300x98.png 300w, https://lycos7560.com/wp-content/uploads/image-141-768x252.png 768w" sizes="(max-width: 1389px) 100vw, 1389px" /></figure>



<div style="height:15px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$npm init -y</pre>



<div style="height:42px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size"> npm(<em>Node Package Manager</em>) 에서 express설치 </p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ npm install express</pre>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size">npm(<em>Node Package Manager</em>) 에서 mysql2 설치</p>



<pre class="EnlighterJSRAW" data-enlighter-language="cpp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">npm install --save mysql2</pre>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-large-font-size">postman 다운로드</p>



<p>&nbsp;<em>Postman</em>은 개발한 API를 테스트하고, 테스트 결과를 공유하여 API 개발의 생산성을 높여주는 플랫폼</p>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<p><a href="https://www.postman.com/">https://www.postman.com/</a></p>



<figure class="wp-block-image size-full"><img decoding="async" width="1343" height="680" src="https://lycos7560.com/wp-content/uploads/image-142.png" alt="" class="wp-image-2440" srcset="https://lycos7560.com/wp-content/uploads/image-142.png 1343w, https://lycos7560.com/wp-content/uploads/image-142-300x152.png 300w, https://lycos7560.com/wp-content/uploads/image-142-768x389.png 768w" sizes="(max-width: 1343px) 100vw, 1343px" /></figure>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1318" height="693" src="https://lycos7560.com/wp-content/uploads/image-143.png" alt="" class="wp-image-2441" srcset="https://lycos7560.com/wp-content/uploads/image-143.png 1318w, https://lycos7560.com/wp-content/uploads/image-143-300x158.png 300w, https://lycos7560.com/wp-content/uploads/image-143-768x404.png 768w" sizes="(max-width: 1318px) 100vw, 1318px" /></figure>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1412" height="896" src="https://lycos7560.com/wp-content/uploads/image-144.png" alt="" class="wp-image-2442" srcset="https://lycos7560.com/wp-content/uploads/image-144.png 1412w, https://lycos7560.com/wp-content/uploads/image-144-300x190.png 300w, https://lycos7560.com/wp-content/uploads/image-144-768x487.png 768w" sizes="(max-width: 1412px) 100vw, 1412px" /></figure>



<div style="height:60px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1205" height="610" src="https://lycos7560.com/wp-content/uploads/image-145.png" alt="" class="wp-image-2443" srcset="https://lycos7560.com/wp-content/uploads/image-145.png 1205w, https://lycos7560.com/wp-content/uploads/image-145-300x152.png 300w, https://lycos7560.com/wp-content/uploads/image-145-768x389.png 768w" sizes="(max-width: 1205px) 100vw, 1205px" /></figure>



<div style="height:36px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const express = require(`express`);
const app = express();

app.get(`/`, function (req, res) {
    res.send(`hello World`);
})

app.listen(포트);</pre>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>공유기 포트 포워딩</strong></h2>



<figure class="wp-block-image size-full"><img decoding="async" width="764" height="131" src="https://lycos7560.com/wp-content/uploads/image-146.png" alt="" class="wp-image-2444" srcset="https://lycos7560.com/wp-content/uploads/image-146.png 764w, https://lycos7560.com/wp-content/uploads/image-146-300x51.png 300w" sizes="(max-width: 764px) 100vw, 764px" /></figure>



<div style="height:39px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading"><strong>포스트맨 확인</strong></h2>



<figure class="wp-block-image size-full"><img decoding="async" width="1212" height="684" src="https://lycos7560.com/wp-content/uploads/image-147.png" alt="" class="wp-image-2445" srcset="https://lycos7560.com/wp-content/uploads/image-147.png 1212w, https://lycos7560.com/wp-content/uploads/image-147-300x169.png 300w, https://lycos7560.com/wp-content/uploads/image-147-768x433.png 768w" sizes="(max-width: 1212px) 100vw, 1212px" /></figure>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="782" height="537" src="https://lycos7560.com/wp-content/uploads/image-148.png" alt="" class="wp-image-2446" srcset="https://lycos7560.com/wp-content/uploads/image-148.png 782w, https://lycos7560.com/wp-content/uploads/image-148-300x206.png 300w, https://lycos7560.com/wp-content/uploads/image-148-768x527.png 768w" sizes="(max-width: 782px) 100vw, 782px" /></figure>



<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1303" height="99" src="https://lycos7560.com/wp-content/uploads/image-149.png" alt="" class="wp-image-2447" srcset="https://lycos7560.com/wp-content/uploads/image-149.png 1303w, https://lycos7560.com/wp-content/uploads/image-149-300x23.png 300w, https://lycos7560.com/wp-content/uploads/image-149-768x58.png 768w" sizes="(max-width: 1303px) 100vw, 1303px" /></figure>



<div style="height:44px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const express = require(`express`);
const app = express();
const port = ;


app.get(`/`, function (req, res) {
    res.send(`hello World`);
});

app.listen(port, () => {
    console.log(`Rest API SERVER 실행됨 port : ${port}`);
});</pre>



<div style="height:106px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-huge-font-size wp-block-heading"><strong>GET POST 차이점</strong></h2>



<p><a href="https://noahlogs.tistory.com/35" target="_blank" rel="noreferrer noopener">https://noahlogs.tistory.com/35</a>   &lt;- 자세한 설명 </p>



<h2 class="wp-block-heading">GET 이란?</h2>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>



<p class="has-medium-font-size">GET 은 클라이언트에서 서버로 어떠한 리소스로부터 정보를 요청하기 위해 사용되는 메서드이다.<br>예를 들면 게시판의 게시물을 조회할 때 쓸 수 있다.<br>GET을 통한 요청은 URL 주소 끝에 파라미터로 포함되어 전송되며, 이 부분을 쿼리 스트링 (query string)이라고 부른다.<br>방식은 URL 끝에 &#8220;? &#8220;를 붙이고 그다음 변수명 1=값 1&amp;변수명 2=값 2… 형식으로 이어 붙이면 된다.<br>예를 들어 다음과 같은 방식이다.<br>www.example.com/show?name1=value1&amp;name2=value2<br>서버에서는 name1과 name2라는 파라미터 명으로 각각 value1과 value2의 파라미터 값을 전달받을 수 있다.</p>



<h2 class="wp-block-heading">GET의 특징</h2>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>



<ul class="wp-block-list">
<li>GET 요청은 캐시가 가능하다.&nbsp;&nbsp;: GET을 통해 서버에 리소스를 요청할 때 웹 캐시가 요청을 가로채 서버로부터 리소스를 다시 다운로드하는 대신 리소스의 복사본을 반환한다. HTTP 헤더에서 cache-control 헤더를 통해 캐시 옵션을 지정할 수 있다.<br></li>



<li>GET 요청은 브라우저 히스토리에 남는다.<br></li>



<li>GET 요청은 북마크 될 수 있다.<br></li>



<li>GET 요청은 길이 제한이 있다.&nbsp;: GET 요청의 길이 제한은 표준이 따로 있는건 아니고 브라우저마다 제한이 다르다고 한다.&nbsp;<br></li>



<li>GET 요청은 중요한 정보를 다루면 안된다. ( 보안 )&nbsp;: GET 요청은 파라미터에 다 노출되어 버리기 때문에 최소한의 보안 의식이라 생각하자.<br></li>



<li>GET은 데이터를 요청할때만 사용 된다.</li>
</ul>



<h2 class="wp-block-heading">POST 란?</h2>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>



<p class="has-medium-font-size">POST는 클라이언트에서 서버로 리소스를 생성하거나 업데이트하기 위해 데이터를 보낼 때 사용되는 메서드다. 예를 들면 게시판에 게시글을 작성하는 작업 등을 할 때 사용할 된다.<br>POST는 전송할 데이터를 HTTP 메시지 body 부분에 담아서 서버로 보낸다. ( body 의 타입은 Content-Type 헤더에 따라 결정된다.)<br>GET에서 URL의 파라미터로 보냈던 name1=value1&amp;name2=value2 가 body에 담겨 보내진다 생각하면 된다.<br>POST로 데이터를 전송할 때 길이 제한이 따로 없어 용량이 큰 데이터를 보낼 때 사용하거나 GET처럼 데이터가 외부적으로 드러나는 건 아니라서 보안이 필요한 부분에 많이 사용된다.<br>( 하지만 데이터를 암호화하지 않으면 body의 데이터도 결국 볼 수 있는 건 똑같다. )<br>POST를 통한 데이터 전송은 보통 HTML form을 통해 서버로 전송된다.</p>



<h2 class="wp-block-heading">POST의 특징</h2>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>



<ul class="wp-block-list">
<li>POST 요청은 캐시되지 않는다.<br></li>



<li>POST 요청은 브라우저 히스토리에 남지 않는다.<br></li>



<li>POST 요청은 북마크 되지 않는다.<br></li>



<li>POST 요청은 데이터 길이에 제한이 없다.</li>
</ul>



<h2 class="wp-block-heading">GET 과 POST 의 차이점&nbsp;</h2>



<hr class="wp-block-separator has-css-opacity is-style-wide"/>



<p class="has-medium-font-size">&nbsp;GET과 POST의 특징만 보아도 차이가 나긴하지만 추가적으로 차이점을 정리해보면 다음과 같다.</p>



<ul class="wp-block-list">
<li><strong>사용목적</strong>&nbsp;: GET은 서버의 리소스에서 데이터를 요청할 때, POST는 서버의 리소스를 새로 생성하거나 업데이트할 때 사용한다.DB로 따지면 GET은 SELECT 에 가깝고, POST는 Create 에 가깝다고 보면 된다.<br></li>



<li><strong>요청에 body 유무</strong>&nbsp;: GET 은 URL 파라미터에 요청하는 데이터를 담아 보내기 때문에 HTTP 메시지에 body가 없다. POST 는 body 에 데이터를 담아 보내기 때문에 당연히 HTTP 메시지에 body가 존재한다.<br></li>



<li><strong>멱등성 (idempotent)</strong>&nbsp;: GET 요청은 멱등이며, POST는 멱등이 아니다.<br></li>
</ul>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<p>멱등이란?</p>



<p class="has-medium-font-size">멱등의 사전적 정의는 연산을 여러 번 적용하더라도 결과가 달라지지 않는 성질을 의미한다.</p>



<p class="has-medium-font-size">GET은 리소스를 조회한다는 점에서 여러 번 요청하더라도 응답이 똑같을 것 이다. 반대로 POST는 리소스를 새로 생성하거나 업데이트할 때 사용되기 때문에 멱등이 아니라고 볼 수 있다. (POST 요청이 발생하면 서버가 변경될 수 있다.)</p>



<p class="has-medium-font-size">GET과 POST는 이런 차이들이 있기 때문에 사용하려는 목적에 맞는 확인한 후에 사용해야한다.</p>



<p class="has-medium-font-size">GET과 POST 이외에도 PUT , DELETE 등을 적절히 사용하는게 좋은데 예를들어 봇의 경우에 사이트를 돌아다니면서 GET 요청을 날린다. 이럴 때 DELETE 등을 GET으로 처리하면 봇에 의해 서버에 있는 리소스들이 삭제 되는 상황이 일어 날수 있다! 항상 기술을 사용할 때&nbsp;<strong>왜</strong>&nbsp;를 잊지말자.</p>



<div style="height:47px" aria-hidden="true" class="wp-block-spacer"></div>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>




<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1287" height="967" src="https://lycos7560.com/wp-content/uploads/image-150.png" alt="" class="wp-image-2448" srcset="https://lycos7560.com/wp-content/uploads/image-150.png 1287w, https://lycos7560.com/wp-content/uploads/image-150-300x225.png 300w, https://lycos7560.com/wp-content/uploads/image-150-768x577.png 768w" sizes="(max-width: 1287px) 100vw, 1287px" /></figure>



<div style="height:43px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-large-font-size wp-block-heading"><strong>citysRouter.js</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const express = require(`express`);
const citysDBC = require(`./citysDBC`);
const router = express.Router();


router.get('/getCitys', async (req, res)=>{
    let res_get_citys = {
        status : 500,
        citys : [] 
    };

    try{
        const rows = await citysDBC.getCitys();
        res_get_citys.status = 200;
        if(rows.length > 0){
            rows.forEach((city)=>{
                res_get_citys.citys.push(city);
            });
        }else{
            console.log('도시 없음');
        }
    }catch(error)
    {
        console.log(error.message);
    }finally
    {
        //응답 
       res.json(res_get_citys);
    }
});

module.exports = router;</pre>



<h2 class="has-huge-font-size wp-block-heading"><strong>app.js</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const express = require(`express`);
const citysRouter = require('./citysRouter');
const app = express();
const port = ;

app.use(express.json()); // json

app.use('/city', citysRouter);

app.get(`/`, function (req, res) {
    res.send(`&lt;h2>Welcome to REST API SERVER. &lt;/h2>`);
});

app.listen(port, () => {
    console.log(`Rest API SERVER 실행됨 port : ${port}`);
});</pre>



<h2 class="has-huge-font-size wp-block-heading"><strong>citysDBC.js</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// get the client
const mysql = require('mysql2');

// Create the connection pool. The pool-specific settings are the defaults
const pool = mysql.createPool({
  host: 'localhost',
  user: '',
  password: '',
  database: '',
  port: ,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
});

const getCitys = async ()=>{
    const promisePool = pool.promise();
    const [rows] = await promisePool.query('SELECT * FROM city;');
    return rows;
};



module.exports = {
    getCitys
};</pre>



<div style="height:33px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size"><strong>완료</strong></p>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1384" height="131" src="https://lycos7560.com/wp-content/uploads/image-151.png" alt="" class="wp-image-2449" srcset="https://lycos7560.com/wp-content/uploads/image-151.png 1384w, https://lycos7560.com/wp-content/uploads/image-151-300x28.png 300w, https://lycos7560.com/wp-content/uploads/image-151-768x73.png 768w" sizes="(max-width: 1384px) 100vw, 1384px" /></figure>



<div style="height:35px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1429" height="675" src="https://lycos7560.com/wp-content/uploads/image-152.png" alt="" class="wp-image-2450" srcset="https://lycos7560.com/wp-content/uploads/image-152.png 1429w, https://lycos7560.com/wp-content/uploads/image-152-300x142.png 300w, https://lycos7560.com/wp-content/uploads/image-152-768x363.png 768w" sizes="(max-width: 1429px) 100vw, 1429px" /></figure>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1464" height="1107" src="https://lycos7560.com/wp-content/uploads/image-153.png" alt="" class="wp-image-2451" srcset="https://lycos7560.com/wp-content/uploads/image-153.png 1464w, https://lycos7560.com/wp-content/uploads/image-153-300x227.png 300w, https://lycos7560.com/wp-content/uploads/image-153-768x581.png 768w" sizes="(max-width: 1464px) 100vw, 1464px" /></figure>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1493" height="1106" src="https://lycos7560.com/wp-content/uploads/image-154.png" alt="" class="wp-image-2452" srcset="https://lycos7560.com/wp-content/uploads/image-154.png 1493w, https://lycos7560.com/wp-content/uploads/image-154-300x222.png 300w, https://lycos7560.com/wp-content/uploads/image-154-768x569.png 768w" sizes="(max-width: 1493px) 100vw, 1493px" /></figure>



<div style="height:93px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-huge-font-size wp-block-heading"><strong>USER 등록 및 검색</strong></h2>



<h2 class="has-large-font-size wp-block-heading">usersDBC.js</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// get the client
const mysql = require('mysql2');

const pool = mysql.createPool({
    host: '',
    user: '',
    password: '',
    database: 'test_schema',
    port: ,
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
  });

  const signup = async (values)=>{
    const promisePool = pool.promise();
    const [rows] = await promisePool.query('insert into users (user_uid, nickname) values (?, ?)', values);
    //console.log(rows);
    return rows;
  };
  
  const getUsers = async ()=>{
    const promisePool = pool.promise();
    const [rows] = await promisePool.query('select * from users;');
    console.log(rows);
    return rows;
  };

  module.exports = {
    getUsers,
    signup
};</pre>



<h2 class="has-large-font-size wp-block-heading">usersRouter.js</h2>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const express = require(`express`);
const userDBC = require(`./usersDBC`);
const router = express.Router();

router.post('/signup', async(req, res)=>{
    const res_signup = {
        status_code : 500
    };

    try{
        const {user_uid, nickname} =  req.body;
        const rows = await userDBC.signup([user_uid, nickname]);
        if(rows.affectedRows > 0){
            // 적용됨 
            res_signup.status_code = 200;
        }else{
            // 적용 안됨 
            res_signup.status_code = 201;
        }
    }catch(err)
    {
        //에러 
        console.log(err.message);
    }finally{
        res.json(res_signup);
    }
});

router.get('/getUsers', async (req, res)=>{
    let res_get_users = {
        status_code : 500,
        users : [] 
    };

    try{
        const rows = await userDBC.getUsers();
        res_get_users.status_code = 200;
        if(rows.length > 0){
            rows.forEach((user)=>{
                res_get_users.users.push({
                    nickname : user.nickname
                });
            });
        }else{
            console.log('사용자 없음');
        }
    }catch(error)
    {
        console.log(error.message);
    }finally
    {
        //응답 
       res.json(res_get_users);
    }
});


module.exports = router;</pre>



<p class="has-large-font-size">app.js</p>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const express = require(`express`);
const citysRouter = require('./citysRouter');
const usersRouter = require('./usersRouter');
const app = express();
const port = ;

app.use(express.json()); // json

app.use('/city', citysRouter);
app.use('/user', usersRouter);

app.get(`/`, function (req, res) {
    res.send(`&lt;h2>Welcome to REST API SERVER. &lt;/h2>`);
});

app.listen(port, () => {
    console.log(`Rest API SERVER 실행됨 port : ${port}`);
});</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1805" height="417" src="https://lycos7560.com/wp-content/uploads/image-155.png" alt="" class="wp-image-2453" srcset="https://lycos7560.com/wp-content/uploads/image-155.png 1805w, https://lycos7560.com/wp-content/uploads/image-155-300x69.png 300w, https://lycos7560.com/wp-content/uploads/image-155-768x177.png 768w, https://lycos7560.com/wp-content/uploads/image-155-1536x355.png 1536w" sizes="(max-width: 1805px) 100vw, 1805px" /></figure>



<div style="height:25px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1515" height="480" src="https://lycos7560.com/wp-content/uploads/image-156.png" alt="" class="wp-image-2454" srcset="https://lycos7560.com/wp-content/uploads/image-156.png 1515w, https://lycos7560.com/wp-content/uploads/image-156-300x95.png 300w, https://lycos7560.com/wp-content/uploads/image-156-768x243.png 768w" sizes="(max-width: 1515px) 100vw, 1515px" /></figure>



<div style="height:21px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1456" height="430" src="https://lycos7560.com/wp-content/uploads/image-157.png" alt="" class="wp-image-2455" srcset="https://lycos7560.com/wp-content/uploads/image-157.png 1456w, https://lycos7560.com/wp-content/uploads/image-157-300x89.png 300w, https://lycos7560.com/wp-content/uploads/image-157-768x227.png 768w" sizes="(max-width: 1456px) 100vw, 1456px" /></figure>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1502" height="642" src="https://lycos7560.com/wp-content/uploads/image-158.png" alt="" class="wp-image-2456" srcset="https://lycos7560.com/wp-content/uploads/image-158.png 1502w, https://lycos7560.com/wp-content/uploads/image-158-300x128.png 300w, https://lycos7560.com/wp-content/uploads/image-158-768x328.png 768w" sizes="(max-width: 1502px) 100vw, 1502px" /></figure>



<div style="height:66px" aria-hidden="true" class="wp-block-spacer"></div>



<p>cd .. 상위 디렉토리<br>cd &#8211; 뒤로가기<br>cd 폴더명 해당 디렉토리로<br>dir 위치의 파일 확인<br>mkdir 폴더명<br>pushd &lt;-UNC 경로 지원 안할때</p>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<p>node js<br>netstat -a 사용중인 포트 보기<br>netstat findstr: 포트 번호<br>(혹은 netstat -an | findstr:&#8221;포트넘버&#8221;) 를 통해 특정한 포트넘버를 직접 찾을 수도 있다.<br>*-an 은 -a와 -n 을 합친 명령어로서 n은 숫자를 의미한다.<br>*findstr 은 특정 문자를 포함한 문자열을 찾는다는 뜻이다.)<br><br>ps -aef | grep node  사용중인 노드 보기<br><br>Taskkill /IM node.exe /F 를 입력해 <br> kill node <br>killall node<br>Node.js 를 통해 실행중인 모든 서버를 종료할 수 있다.<br></p>



<p>taskkill /f /pid (종료할 pid) 를 입력하여 특정 pid를 가진 연결을 종료시킨다.<br>(pid는 맨 오른쪽에 있는 숫자가 pid이다.)</p>



<ul class="wp-block-list">
<li>pid 란 process ID 를 뜻한다.</li>
</ul>



<div style="height:91px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">연습용 프로토콜 문서</h2>



<div style="height:28px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1698" height="818" src="https://lycos7560.com/wp-content/uploads/image-159.png" alt="" class="wp-image-2457" srcset="https://lycos7560.com/wp-content/uploads/image-159.png 1698w, https://lycos7560.com/wp-content/uploads/image-159-300x145.png 300w, https://lycos7560.com/wp-content/uploads/image-159-768x370.png 768w, https://lycos7560.com/wp-content/uploads/image-159-1536x740.png 1536w" sizes="(max-width: 1698px) 100vw, 1698px" /></figure>



<div style="height:31px" aria-hidden="true" class="wp-block-spacer"></div>



<div class="wp-block-file"><a id="wp-block-file--media-2f53af65-3724-4d8b-be83-c8df0a03ea72" href="https://lycos7560.com/wp-content/uploads/Test_Protocol_Document.xlsx">Test_Protocol_Document</a><a href="https://lycos7560.com/wp-content/uploads/Test_Protocol_Document.xlsx" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-2f53af65-3724-4d8b-be83-c8df0a03ea72">다운로드</a></div>



<div style="height:41px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-large-font-size wp-block-heading"><strong>usersRouter.js</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const express = require(`express`);
const userDBC = require(`./usersDBC`);
const router = express.Router();

router.post('/signUp', async(req, res)=>{
    const res_signup = {
        status_code : 500
    };

    try{
        const {user_uid, nickname} =  req.body;
        const rows = await userDBC.signUp([user_uid, nickname]);
        if(rows.affectedRows > 0){
            //적용됨 
            res_signup.status_code = 200;
        }else{
            //적용안됨 
            res_signup.status_code = 201;
        }
    }catch(err)
    {
        //에러 
        console.log(err.message);
    }finally{
        res.json(res_signup);
    }
});

router.get('/getUsers', async (req, res)=>{
    let res_get_users = {
        status_code : 500,
        users : [] 
    };

    try{
        const rows = await userDBC.getUsers();
        res_get_users.status_code = 200;
        if(rows.length > 0){
            rows.forEach((user)=>{
                res_get_users.users.push({
                    nickname : user.nickname
                });
            });
        }else{
            console.log('사용자 없음');
        }
    }catch(error)
    {
        console.log(error.message);
    }finally
    {
        //응답 
       res.json(res_get_users);
    }
});


router.post('/nasSignUp', async(req, res)=>{

    const res_signup = {
        status_Code : 500
    };

    try{
        //console.log(req.body);
        const {user_uid, nickname} =  req.body;
        const row = await userDBC.nasSignUp([user_uid, nickname]);
        if(row.length > 0)
        {
            res_signup.status_Code = row[0];
        }

    }catch(err)
    {
        //에러 
        console.log(err.message);
    }finally{
        res.json(res_signup.status_Code);
    }


});

router.post('/nasGetUser', async(req, res)=>{

    const res_getuser = {
        statusCode : 500,
        nickname : ""
    };

    try{
        const {user_uid} =  req.body;
        const row = await userDBC.nasGetUser([user_uid]);
        const row2 = await userDBC.nasGetUserNick([user_uid]);
        if(row.length > 0)
        {
            res_getuser.statusCode = row[0].statusCode;
            res_getuser.nickname = row2[0].nickname; 

        }
        console.log(row);
    }
    catch(err)
    {
        //에러 
        console.log(err.message);
    }
    finally{
        res.json(res_getuser);
    }
});


router.post('/nasSignOut', async(req, res)=>{

    const res_signup = {
        status_Code : 500
    };

    try{
        const {user_uid} =  req.body;
        const row = await userDBC.nasSignOut([user_uid]);
        if(row.length > 0)
        {
            res_signup.status_Code = row[0];
        }
    }catch(err)
    {
        //에러 
        console.log(err.message);
    }finally{
        res.json(res_signup.status_Code);
    }

});


module.exports = router;</pre>



<h2 class="has-large-font-size wp-block-heading"><strong>usersDBC.js</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">// get the client
const mysql = require('mysql2');

const pool = mysql.createPool({
    host: '
    user: '
    password: '
    database: '
    port: 
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
  });

  const signUp = async (values)=>{
    const promisePool = pool.promise();
    const [rows] = await promisePool.query('insert into users (user_uid, nickname) values (?, ?)', values);
    //console.log(rows);
    return rows;
  };
  
  const getUsers = async ()=>{
    const promisePool = pool.promise();
    const [rows] = await promisePool.query('select * from users;');
    console.log(rows);
    return rows;
  };

  const signOut = async () => {
    const promisePool = pool.promise();
    const [rows] = await promisePool.query(``)

  };


  const nasSignUp = async ([user_uid, nickname])=>{
    const promisePool = pool.promise();
    //console.log(user_uid);
    //console.log(nickname);
    const [rows] = await promisePool.query(`SELECT FNC_sign_Up('${user_uid}','${nickname}') AS statusCode;`);
    //console.log(rows);
    return rows;
  };

  const nasGetUser = async ([user_uid])=>{
    const promisePool = pool.promise();
    const [rows] = await promisePool.query(`SELECT FNC_getUser_statusCode('${user_uid}') AS statusCode;`);
    return rows;
  };

  const nasGetUserNick = async ([user_uid])=>{
    const promisePool = pool.promise();
    const [rows] = await promisePool.query(`SELECT FNC_getUser_nickName('${user_uid}') AS nickname;`);
    return rows;
  };

  const nasSignOut = async ([user_uid])=>{
    const promisePool = pool.promise();
    const [rows] = await promisePool.query(`SELECT FNC_signOut('${user_uid}') AS statusCode;`);
    return rows;
  };



  module.exports = {
    getUsers,
    signUp,
    signOut,
    nasSignUp,
    nasGetUser, 
    nasGetUserNick,
    nasSignOut
};</pre>



<h2 class="has-large-font-size wp-block-heading"><strong>app.js</strong></h2>



<pre class="EnlighterJSRAW" data-enlighter-language="js" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">const express = require(`express`);
const citysRouter = require('./citysRouter');
const usersRouter = require('./usersRouter');
const app = express();
const port = ;

app.use(express.json()); // json

app.use('/city', citysRouter);
app.use('/user', usersRouter);

app.get(`/`, function (req, res) {
    res.send(`&lt;h2>Welcome to REST API SERVER. &lt;/h2>`);
});

app.listen(port, () => {
    console.log(`Rest API SERVER 실행됨 port : ${port}`);
});</pre>



<div style="height:99px" aria-hidden="true" class="wp-block-spacer"></div>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-large-font-size wp-block-heading">Query</h2>



<div class="wp-block-file"><a id="wp-block-file--media-b9a8541d-271b-4a52-80ee-5fb8d565c3dc" href="https://lycos7560.com/wp-content/uploads/TestRestServerQuery.7z">TestRestServerQuery</a><a href="https://lycos7560.com/wp-content/uploads/TestRestServerQuery.7z" class="wp-block-file__button wp-element-button" download aria-describedby="wp-block-file--media-b9a8541d-271b-4a52-80ee-5fb8d565c3dc">다운로드</a></div>



<div style="height:12px" aria-hidden="true" class="wp-block-spacer"></div>



<pre class="EnlighterJSRAW" data-enlighter-language="sql" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">USE test_schema;
SELECT * FROM users;
DELETE FROM users WHERE user_uid = '445a6a0a-577f-4ae4-b6f3-6f1301380edf';



## 유저를 등록
delimiter //
CREATE FUNCTION FNC_sign_Up($user_uid varchar(45), $nickName varchar(45)) RETURNS INT
BEGIN
SET @user_uid_duplicate_check = 0;  -- 유저 uid로 검색하여 중복 체크 
SET @nickname_duplicate_check = 0;  -- 닉네임 중복 체크 
SET @statusCode = 200; -- 기본으로 200 
-- 200	유저 등록 완료
-- 201	이미 등록된 유저
-- 202	중복 닉네임
-- 500	서버 에러
	select count(*) into @user_uid_duplicate_check from users where user_uid = $user_uid;
    select count(*) into @nickname_duplicate_check from users where nickName = $nickName;
    
    CASE
		WHEN @user_uid_duplicate_check > 0 THEN set @statusCode = 201; -- 이미 등록된 유저 
		WHEN @nickname_duplicate_check > 0 THEN set @statusCode = 202; -- 이미 등록된 닉네임
        ELSE INSERT INTO users (user_uid, nickname) values ($user_uid, $nickName);
	END case;
    
	return @statusCode;  -- 처리 결과를 반환함 
END //
delimiter ;

SHOW function status;
DROP FUNCTION FNC_sign_Up;

SELECT FNC_sign_Up('13978557c-2810-4cbf-bd4b-1d4decac45d3', '최토리') AS status_Code;
SELECT FNC_sign_Up('445a6a0a-577f-4ae4-b6f3-6f1301380edf', '토리') AS status_Code;






## 유저를 검색
delimiter //
CREATE FUNCTION FNC_getUser_statusCode($user_uid varchar(45)) RETURNS INT
BEGIN
SET @user_uid_duplicate_check = 0;  -- 유저 uid로 검색하여 체크
SET @statusCode = 500; -- 기본으로 500 
-- 200	유저 검색 완료
-- 201	등록 되지 않은 유저
-- 500	서버 에러
	select count(*) into @user_uid_duplicate_check from users where user_uid = $user_uid;

    CASE
		WHEN @user_uid_duplicate_check = 0 THEN set @statusCode = 201; -- 등록 되지 않은 유저 
        WHEN @user_uid_duplicate_check = 1 THEN set @statusCode = 200; -- 등록된 유저 
	END case;
    
	return @statusCode;  -- 처리 결과를 반환함 
END //
delimiter ;

SELECT FNC_getUser_statusCode('13978557c-2810-4cbf-bd4b-1d4decac45d3') AS statusCode;


SHOW function status;

DROP FUNCTION FNC_getUser_statusCode;


## UID로 유저를 검색
delimiter //
CREATE FUNCTION FNC_getUser_nickName($user_uid varchar(45)) RETURNS varchar(45)
BEGIN
	declare tnickname varchar(45);
    select nickname into tnickname  from users where user_uid = $user_uid;
	return tnickname;
END //
delimiter ;

SELECT FNC_getUser_nickName('445a6a0a-577f-4ae4-b6f3-6f1301380edf') AS nickname;

DROP FUNCTION FNC_getUser_nickName;







## 유저를 삭제
delimiter //
CREATE FUNCTION FNC_signOut($user_uid varchar(45)) RETURNS INT
BEGIN
SET @user_uid_duplicate_check = 0;  -- 유저 uid로 검색하여 체크
SET @statusCode = 500; -- 기본으로 500 
-- 200	유저 탈퇴 완료
-- 201	등록 되지 않은 유저
-- 500	서버 에러

	select count(*) into @user_uid_duplicate_check from users where user_uid = $user_uid;

    CASE
		WHEN @user_uid_duplicate_check = 0 THEN set @statusCode = 201; -- 등록 되지 않은 유저 
        WHEN @user_uid_duplicate_check = 1 THEN set @statusCode = 200;
			 DELETE FROM users WHERE user_uid = $user_uid;  -- 등록된 유저 
	END case;
    
	return @statusCode;  -- 처리 결과를 반환함 
END //
delimiter ;

DROP FUNCTION FNC_signOut;

SELECT FNC_signOut('13978557c-2810-4cbf-bd4b-1d4decac45d3') AS statusCode;
</pre>



<div style="height:127px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-large-font-size wp-block-heading">이제 간단하게 클라이언트(유니티)와 상호작용을 해보자</h2>



<p class="has-medium-font-size">일단 계정을 등록하고 그 결과를 받아오는 부분을 해보겠습니다.</p>



<div style="height:27px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1791" height="919" src="https://lycos7560.com/wp-content/uploads/image-160.png" alt="" class="wp-image-2460" srcset="https://lycos7560.com/wp-content/uploads/image-160.png 1791w, https://lycos7560.com/wp-content/uploads/image-160-300x154.png 300w, https://lycos7560.com/wp-content/uploads/image-160-768x394.png 768w, https://lycos7560.com/wp-content/uploads/image-160-1536x788.png 1536w" sizes="(max-width: 1791px) 100vw, 1791px" /></figure>



<div style="height:13px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1790" height="431" src="https://lycos7560.com/wp-content/uploads/image-161.png" alt="" class="wp-image-2461" srcset="https://lycos7560.com/wp-content/uploads/image-161.png 1790w, https://lycos7560.com/wp-content/uploads/image-161-300x72.png 300w, https://lycos7560.com/wp-content/uploads/image-161-768x185.png 768w, https://lycos7560.com/wp-content/uploads/image-161-1536x370.png 1536w" sizes="(max-width: 1790px) 100vw, 1790px" /></figure>



<div style="height:13px" aria-hidden="true" class="wp-block-spacer"></div>



<p>일단 유저의 Uid는 개인적으로 생성한 것 입니다. <br><br><a href="https://www.uuidgenerator.net/" target="_blank" rel="noreferrer noopener">https://www.uuidgenerator.net/</a>   &lt;- UUID 생성 사이트<br><br>닉네임을 입력하고 등록하면 유저의 Uid/nickname이 중복인지 확인을 하고 해당 결과를 보내줍니다. <br></p>



<div style="height:29px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading">테이블의 상태</h2>



<figure class="wp-block-image size-full"><img decoding="async" width="1248" height="362" src="https://lycos7560.com/wp-content/uploads/image-162.png" alt="" class="wp-image-2462" srcset="https://lycos7560.com/wp-content/uploads/image-162.png 1248w, https://lycos7560.com/wp-content/uploads/image-162-300x87.png 300w, https://lycos7560.com/wp-content/uploads/image-162-768x223.png 768w" sizes="(max-width: 1248px) 100vw, 1248px" /></figure>



<div style="height:32px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading">서버 OFF 상태</h2>



<div style="height:12px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1808" height="539" src="https://lycos7560.com/wp-content/uploads/image-163.png" alt="" class="wp-image-2463" srcset="https://lycos7560.com/wp-content/uploads/image-163.png 1808w, https://lycos7560.com/wp-content/uploads/image-163-300x89.png 300w, https://lycos7560.com/wp-content/uploads/image-163-768x229.png 768w, https://lycos7560.com/wp-content/uploads/image-163-1536x458.png 1536w" sizes="(max-width: 1808px) 100vw, 1808px" /></figure>



<div style="height:9px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1800" height="481" src="https://lycos7560.com/wp-content/uploads/image-164.png" alt="" class="wp-image-2464" srcset="https://lycos7560.com/wp-content/uploads/image-164.png 1800w, https://lycos7560.com/wp-content/uploads/image-164-300x80.png 300w, https://lycos7560.com/wp-content/uploads/image-164-768x205.png 768w, https://lycos7560.com/wp-content/uploads/image-164-1536x410.png 1536w" sizes="(max-width: 1800px) 100vw, 1800px" /></figure>



<div style="height:58px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-medium-font-size wp-block-heading"> 서버 ON 상태 &#8211; 유저 등록 성공</h2>



<div style="height:12px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1804" height="582" src="https://lycos7560.com/wp-content/uploads/image-165.png" alt="" class="wp-image-2465" srcset="https://lycos7560.com/wp-content/uploads/image-165.png 1804w, https://lycos7560.com/wp-content/uploads/image-165-300x97.png 300w, https://lycos7560.com/wp-content/uploads/image-165-768x248.png 768w, https://lycos7560.com/wp-content/uploads/image-165-1536x496.png 1536w" sizes="(max-width: 1804px) 100vw, 1804px" /></figure>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:7px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">데이터가 잘 들어온 것을 확인 할 수 있다. </p>



<div style="height:9px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1815" height="492" src="https://lycos7560.com/wp-content/uploads/image-166.png" alt="" class="wp-image-2466" srcset="https://lycos7560.com/wp-content/uploads/image-166.png 1815w, https://lycos7560.com/wp-content/uploads/image-166-300x81.png 300w, https://lycos7560.com/wp-content/uploads/image-166-768x208.png 768w, https://lycos7560.com/wp-content/uploads/image-166-1536x416.png 1536w" sizes="(max-width: 1815px) 100vw, 1815px" /></figure>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="wp-block-heading">SignUP 작업만 완료된 코드</h2>



<p class="has-medium-font-size">HTTPManager.cs</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using Newtonsoft.Json;
using System.Text;

public class HTTPManager : MonoBehaviour
{
    public static HTTPManager instance;
    public string host = "";
    public int port = ;

    public System.Action&lt;int> getSignUpResult;

    // 싱글톤으로 만들어주자
    private void Awake()
    {
        HTTPManager.instance = this;

    }
    private void OnDestroy()
    {
        HTTPManager.instance = null;
    }

    // uri => /user/signup
    public void RequestSignup(string uri, Packets.req_nasSignUp packet)
    {
        StartCoroutine(this.RequestSignupImpl(uri, packet));
    }

    private IEnumerator RequestSignupImpl(string uri, Packets.req_nasSignUp packet)
    {
        
        var url = string.Format("{0}:{1}{2}", this.host, this.port, uri);
        Debug.Log(url);
        var www = new UnityWebRequest(url, "POST");
        //객체를 -> 문자열 직렬화 
        var json = JsonConvert.SerializeObject(packet);
        //문자열 -> byte배열로 직렬화 
        var rawdata = Encoding.UTF8.GetBytes(json);

        www.uploadHandler = new UploadHandlerRaw(rawdata);  //요청
        www.downloadHandler = new DownloadHandlerBuffer();  //응답 
        www.SetRequestHeader("Content-Type", "application/json");
        yield return www.SendWebRequest();
    
        if (www.result == UnityWebRequest.Result.Success)
        {
            Debug.LogFormat("--->{0}", www.downloadHandler.text);
            var res_signup = JsonConvert.DeserializeObject&lt;Packets.res_nasSignUp>(www.downloadHandler.text);    //역직렬화 
            Debug.LogFormat("status : {0}", res_signup.statusCode);
            this.getSignUpResult(res_signup.statusCode);
        }
        else
        {

            this.getSignUpResult(500);
            Debug.LogFormat("에러");
        }

        www.Dispose();
    }
    
}
</pre>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Packets.cs</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Packets
{



    /*  유저 등록(/users/nasSignUp)
        statusCode
        200	유저 등록 완료
        201	이미 등록된 유저
        202	중복 닉네임
        500	서버 에러
    */


    public class req_nasSignUp
    {
        public string user_uid;
        public string nickname;
    }

    public class res_nasSignUp
    {
        public int statusCode;
    }




    /*  유저 검색 (/users/nasGetUser)
        statusCode
        200	유저 검색 완료
        201	등록 되지 않는 유저
        500	서버 에러
    */

    public class req_nasGetUser
    {
        public string user_uid;
    }

    public class res_nasGetUser
    {
        public int status_code;
        public string users;
    }


}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">RestTestMain.cs</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;


public class RestTestMain : MonoBehaviour
{
    public TMP_Text tmp_User_Uid;
    private string user_Uid;

    public TMP_InputField userNickName_IF;
    private string user_NickName;

    public Button sighUpBtn;
    public TMP_Text result_Text;


    void Start()
    {
        this.user_Uid = tmp_User_Uid.text;

        HTTPManager.instance.getSignUpResult = (packet) =>
        {
            Debug.LogFormat("HTTPManager.instance.getSignUpResult : {0}", packet) ;
            switch (packet)
            {
                case 200:
                    this.result_Text.text = string.Format("status_code : {0}, 유저 등록 완료", packet);
                    break;
                case 201:
                    this.result_Text.text = string.Format("status_code : {0}, 이미 등록된 유저입니다.", packet);
                    break;
                case 202:
                    this.result_Text.text = string.Format("status_code : {0}, 중복된 닉네임 입니다.", packet);
                    break;
                case 500:
                    this.result_Text.text = string.Format("status_code : {0}, 서버가 응답이 없습니다.", packet);
                    break;
                default:
                    this.result_Text.text = string.Format("status_code : {0}, 이거 뜨면 망하는 겁니다.", packet);
                    break;
            }
        };


        this.sighUpBtn.onClick.AddListener(() =>
        {
            this.user_NickName = this.userNickName_IF.text;
            Debug.LogFormat("TMP_InputField : {0}", this.user_NickName);
            if (string.IsNullOrEmpty(this.user_NickName) &amp;&amp; string.IsNullOrEmpty(this.user_Uid))
            {
                Debug.Log("닉네임을 입력해주세요.");
            }
            else
            {
                Debug.LogFormat("{0}, {1}", this.user_Uid, this.user_NickName);
                var packet = new Packets.req_nasSignUp()
                {
                    user_uid = this.user_Uid,
                    nickname = this.user_NickName
                };
                HTTPManager.instance.RequestSignup("/user/nasSignUp",packet);
            }
        });
    }

    
}
</pre>



<p><br>유니티에서 메모리 누수 오류가 뜨면 하단부를 추가하자<br></p>



<figure class="wp-block-image size-full"><img decoding="async" width="222" height="115" src="https://lycos7560.com/wp-content/uploads/image-114-2.png" alt="" class="wp-image-2472"/></figure>



<div style="height:64px" aria-hidden="true" class="wp-block-spacer"></div>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="4245812909"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<div style="height:100px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-large-font-size wp-block-heading"><strong>다음은 Uid로 유저를 검색해보자</strong></h2>



<p>항상 느끼는 거지만 코드를 작성하는 것보다 환경 구성하는 게 제일 화가 난다.</p>



<div style="height:23px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1435" height="303" src="https://lycos7560.com/wp-content/uploads/image-167.png" alt="" class="wp-image-2473" srcset="https://lycos7560.com/wp-content/uploads/image-167.png 1435w, https://lycos7560.com/wp-content/uploads/image-167-300x63.png 300w, https://lycos7560.com/wp-content/uploads/image-167-768x162.png 768w" sizes="(max-width: 1435px) 100vw, 1435px" /></figure>



<div style="height:17px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1317" height="190" src="https://lycos7560.com/wp-content/uploads/image-168.png" alt="" class="wp-image-2474" srcset="https://lycos7560.com/wp-content/uploads/image-168.png 1317w, https://lycos7560.com/wp-content/uploads/image-168-300x43.png 300w, https://lycos7560.com/wp-content/uploads/image-168-768x111.png 768w" sizes="(max-width: 1317px) 100vw, 1317px" /></figure>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1498" height="774" src="https://lycos7560.com/wp-content/uploads/image-169.png" alt="" class="wp-image-2475" srcset="https://lycos7560.com/wp-content/uploads/image-169.png 1498w, https://lycos7560.com/wp-content/uploads/image-169-300x155.png 300w, https://lycos7560.com/wp-content/uploads/image-169-768x397.png 768w" sizes="(max-width: 1498px) 100vw, 1498px" /></figure>



<div style="height:24px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1323" height="953" src="https://lycos7560.com/wp-content/uploads/image-170.png" alt="" class="wp-image-2476" srcset="https://lycos7560.com/wp-content/uploads/image-170.png 1323w, https://lycos7560.com/wp-content/uploads/image-170-300x216.png 300w, https://lycos7560.com/wp-content/uploads/image-170-768x553.png 768w" sizes="(max-width: 1323px) 100vw, 1323px" /></figure>



<div style="height:18px" aria-hidden="true" class="wp-block-spacer"></div>



<div style="height:75px" aria-hidden="true" class="wp-block-spacer"></div>



<p>서버 OFF</p>



<figure class="wp-block-image size-full"><img decoding="async" width="1392" height="316" src="https://lycos7560.com/wp-content/uploads/image-171.png" alt="" class="wp-image-2477" srcset="https://lycos7560.com/wp-content/uploads/image-171.png 1392w, https://lycos7560.com/wp-content/uploads/image-171-300x68.png 300w, https://lycos7560.com/wp-content/uploads/image-171-768x174.png 768w" sizes="(max-width: 1392px) 100vw, 1392px" /></figure>



<div style="height:83px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">HTTPManager.cs &#8211; GetUser 추가</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using Newtonsoft.Json;
using System.Text;

public class HTTPManager : MonoBehaviour
{
    public static HTTPManager instance;
    public string host = "";
    public int port = ;

    public System.Action&lt;int> getSignUpResult;
    public System.Action&lt;Packets.res_nasGetUser> getGetUserResult;

    // 싱글톤으로 만들어주자
    private void Awake()
    {
        HTTPManager.instance = this;

    }
    private void OnDestroy()
    {
        HTTPManager.instance = null;
    }

    // uri => /user/signup
    public void RequestSignup(string uri, Packets.req_nasSignUp packet)
    {
        StartCoroutine(this.RequestSignupImpl(uri, packet));
    }

    private IEnumerator RequestSignupImpl(string uri, Packets.req_nasSignUp packet)
    {
        
        var url = string.Format("{0}:{1}{2}", this.host, this.port, uri);
        Debug.Log(url);
        var www = new UnityWebRequest(url, "POST");
        //객체를 -> 문자열 직렬화 
        var json = JsonConvert.SerializeObject(packet);
        //문자열 -> byte배열로 직렬화 
        var rawdata = Encoding.UTF8.GetBytes(json);

        www.uploadHandler = new UploadHandlerRaw(rawdata);  //요청
        www.downloadHandler = new DownloadHandlerBuffer();  //응답 
        www.SetRequestHeader("Content-Type", "application/json");
        yield return www.SendWebRequest();
    
        if (www.result == UnityWebRequest.Result.Success)
        {
            Debug.LogFormat("--->{0}", www.downloadHandler.text);
            var res_signup = JsonConvert.DeserializeObject&lt;Packets.res_nasSignUp>(www.downloadHandler.text);    //역직렬화 
            Debug.LogFormat("status : {0}", res_signup.statusCode);
            this.getSignUpResult(res_signup.statusCode);
        }
        else
        {

            this.getSignUpResult(500);
            Debug.LogFormat("에러");
        }

        www.Dispose();
    }

    public void RequestGetUser(string uri, Packets.req_nasGetUser packet)
    {
        StartCoroutine(this.RequestGetUserImpl(uri, packet));
    }

    private IEnumerator RequestGetUserImpl(string uri, Packets.req_nasGetUser packet)
    {

        var url = string.Format("{0}:{1}{2}", this.host, this.port, uri);
        Debug.Log(url);
        var www = new UnityWebRequest(url, "POST");
        //객체를 -> 문자열 직렬화 
        var json = JsonConvert.SerializeObject(packet);
        //문자열 -> byte배열로 직렬화 
        var rawdata = Encoding.UTF8.GetBytes(json);

        www.uploadHandler = new UploadHandlerRaw(rawdata);  //요청
        www.downloadHandler = new DownloadHandlerBuffer();  //응답 
        www.SetRequestHeader("Content-Type", "application/json");
        yield return www.SendWebRequest();

        if (www.result == UnityWebRequest.Result.Success)
        {
            Debug.LogFormat("--->{0}", www.downloadHandler.text);
            var res_getuser = JsonConvert.DeserializeObject&lt;Packets.res_nasGetUser>(www.downloadHandler.text);    //역직렬화 
            Debug.LogFormat("status : {0}, nickName : {1}", res_getuser.statusCode, res_getuser.nickname);
            this.getGetUserResult(res_getuser);
        }
        else
        {
            Packets.res_nasGetUser res_getuser = new Packets.res_nasGetUser();
            res_getuser.statusCode = 500;
            res_getuser.nickname = "";
            this.getGetUserResult(res_getuser);
            Debug.LogFormat("에러");
        }

        www.Dispose();
    }

}
</pre>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Packets.cs  &#8211; GetUser 추가 </p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Packets
{



    /*  유저 등록(/users/nasSignUp)
        statusCode
        200	유저 등록 완료
        201	이미 등록된 유저
        202	중복 닉네임
        500	서버 에러
    */


    public class req_nasSignUp
    {
        public string user_uid;
        public string nickname;
    }

    public class res_nasSignUp
    {
        public int statusCode;
    }




    /*  유저 검색 (/users/nasGetUser)
        statusCode
        200	유저 검색 완료
        201	등록 되지 않는 유저
        500	서버 에러
    */

    public class req_nasGetUser
    {
        public string user_uid;
    }

    public class res_nasGetUser
    {
        public int statusCode;
        public string nickname;
    }


}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">RestTestMain.cs  &#8211; GetUser 추가 </p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;


public class RestTestMain : MonoBehaviour
{
    public Button SignUpTabBtn;
    public Button GetUserTabBtn;

    public GameObject SignUpGO;
    public GameObject GetUserGO;

    public TMP_Text tmp_User_Uid;
    private string user_Uid;

    public TMP_InputField userNickName_IF;
    private string user_NickName;

    public TMP_InputField UserUid_IF;

    public Button sighUpBtn;
    public Button getUserBtn;


    public TMP_Text result_Text;


    void Start()
    {
        this.user_Uid = tmp_User_Uid.text;

        this.SignUpTabBtn.onClick.AddListener(() => {
            this.SignUpGO.SetActive(true);
            this.GetUserGO.SetActive(false);
        });

        this.GetUserTabBtn.onClick.AddListener(() => {
            this.SignUpGO.SetActive(false);
            this.GetUserGO.SetActive(true);
        });

        


        HTTPManager.instance.getSignUpResult = (packet) =>
        {
            Debug.LogFormat("HTTPManager.instance.getSignUpResult : {0}", packet) ;
            switch (packet)
            {
                case 200:
                    this.result_Text.text = string.Format("status_code : {0}, 유저 등록 완료", packet);
                    break;
                case 201:
                    this.result_Text.text = string.Format("status_code : {0}, 이미 등록된 유저입니다.", packet);
                    break;
                case 202:
                    this.result_Text.text = string.Format("status_code : {0}, 중복된 닉네임 입니다.", packet);
                    break;
                case 500:
                    this.result_Text.text = string.Format("status_code : {0}, 서버가 응답이 없습니다.", packet);
                    break;
                default:
                    this.result_Text.text = string.Format("status_code : {0}, 이거 뜨면 망하는 겁니다.", packet);
                    break;
            }
        };


        HTTPManager.instance.getGetUserResult = (packet) => {

            switch (packet.statusCode)
            {
                case 200:
                    this.result_Text.text = string.Format("status_code : {0}, 유저 검색 완료\n", packet.statusCode);
                    this.result_Text.text += string.Format("NickName : {0}", packet.nickname);
                    break;
                case 201:
                    this.result_Text.text = string.Format("status_code : {0}, 서버에 등록되지 않은 유저입니다.", packet.statusCode);
                    break;
                case 500:
                    this.result_Text.text = string.Format("status_code : {0}, 서버가 응답이 없습니다.", packet.statusCode);
                    break;
                default:
                    this.result_Text.text = string.Format("status_code : {0}, 이거 뜨면 망하는 겁니다.", packet.statusCode);
                    break;
            }



        };


        this.sighUpBtn.onClick.AddListener(() =>
        {
            this.user_NickName = this.userNickName_IF.text;
            Debug.LogFormat("TMP_InputField : {0}", this.user_NickName);
            if (string.IsNullOrEmpty(this.user_NickName) &amp;&amp; string.IsNullOrEmpty(this.user_Uid))
            {
                this.result_Text.text = string.Format("닉네임을 입력해주세요.");
            }
            else
            {
                Debug.LogFormat("{0}, {1}", this.user_Uid, this.user_NickName);
                var packet = new Packets.req_nasSignUp()
                {
                    user_uid = this.user_Uid,
                    nickname = this.user_NickName
                };
                HTTPManager.instance.RequestSignup("/user/nasSignUp",packet);
            }
        });

        this.getUserBtn.onClick.AddListener(() => {

            if (string.IsNullOrEmpty(this.UserUid_IF.text))
            {
                this.result_Text.text = string.Format("유저의 UID를 입력해주세요.");
            }
            else
            {
                var packet = new Packets.req_nasGetUser()
                {
                    user_uid = this.UserUid_IF.text
                };
                HTTPManager.instance.RequestGetUser("/user/nasGetUser", packet);
            }


        });


    }

    
}
</pre>



<div style="height:45px" aria-hidden="true" class="wp-block-spacer"></div>



<h2 class="has-large-font-size wp-block-heading"><strong> 다음은 Uid로 유저를 삭제해보자</strong></h2>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1365" height="278" src="https://lycos7560.com/wp-content/uploads/image-172.png" alt="" class="wp-image-2478" srcset="https://lycos7560.com/wp-content/uploads/image-172.png 1365w, https://lycos7560.com/wp-content/uploads/image-172-300x61.png 300w, https://lycos7560.com/wp-content/uploads/image-172-768x156.png 768w" sizes="(max-width: 1365px) 100vw, 1365px" /></figure>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1370" height="609" src="https://lycos7560.com/wp-content/uploads/image-173.png" alt="" class="wp-image-2479" srcset="https://lycos7560.com/wp-content/uploads/image-173.png 1370w, https://lycos7560.com/wp-content/uploads/image-173-300x133.png 300w, https://lycos7560.com/wp-content/uploads/image-173-768x341.png 768w" sizes="(max-width: 1370px) 100vw, 1370px" /></figure>



<div style="height:7px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1022" height="190" src="https://lycos7560.com/wp-content/uploads/image-174.png" alt="" class="wp-image-2480" srcset="https://lycos7560.com/wp-content/uploads/image-174.png 1022w, https://lycos7560.com/wp-content/uploads/image-174-300x56.png 300w, https://lycos7560.com/wp-content/uploads/image-174-768x143.png 768w" sizes="(max-width: 1022px) 100vw, 1022px" /></figure>



<div style="height:9px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1335" height="314" src="https://lycos7560.com/wp-content/uploads/image-175.png" alt="" class="wp-image-2481" srcset="https://lycos7560.com/wp-content/uploads/image-175.png 1335w, https://lycos7560.com/wp-content/uploads/image-175-300x71.png 300w, https://lycos7560.com/wp-content/uploads/image-175-768x181.png 768w" sizes="(max-width: 1335px) 100vw, 1335px" /></figure>



<div style="height:9px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="799" height="126" src="https://lycos7560.com/wp-content/uploads/image-176.png" alt="" class="wp-image-2482" srcset="https://lycos7560.com/wp-content/uploads/image-176.png 799w, https://lycos7560.com/wp-content/uploads/image-176-300x47.png 300w, https://lycos7560.com/wp-content/uploads/image-176-768x121.png 768w" sizes="(max-width: 799px) 100vw, 799px" /></figure>



<div style="height:8px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1311" height="274" src="https://lycos7560.com/wp-content/uploads/image-177.png" alt="" class="wp-image-2483" srcset="https://lycos7560.com/wp-content/uploads/image-177.png 1311w, https://lycos7560.com/wp-content/uploads/image-177-300x63.png 300w, https://lycos7560.com/wp-content/uploads/image-177-768x161.png 768w" sizes="(max-width: 1311px) 100vw, 1311px" /></figure>



<div style="height:8px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="874" height="154" src="https://lycos7560.com/wp-content/uploads/image-178.png" alt="" class="wp-image-2484" srcset="https://lycos7560.com/wp-content/uploads/image-178.png 874w, https://lycos7560.com/wp-content/uploads/image-178-300x53.png 300w, https://lycos7560.com/wp-content/uploads/image-178-768x135.png 768w" sizes="(max-width: 874px) 100vw, 874px" /></figure>



<div style="height:10px" aria-hidden="true" class="wp-block-spacer"></div>



<figure class="wp-block-image size-full"><img decoding="async" width="1436" height="291" src="https://lycos7560.com/wp-content/uploads/image-179.png" alt="" class="wp-image-2485" srcset="https://lycos7560.com/wp-content/uploads/image-179.png 1436w, https://lycos7560.com/wp-content/uploads/image-179-300x61.png 300w, https://lycos7560.com/wp-content/uploads/image-179-768x156.png 768w" sizes="(max-width: 1436px) 100vw, 1436px" /></figure>



<div style="height:83px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">HTTPManager.cs &#8211; SignOut 추가</p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using Newtonsoft.Json;
using System.Text;

public class HTTPManager : MonoBehaviour
{
    public static HTTPManager instance;
    public string host = "";
    public int port = ;

    public System.Action&lt;int> getSignUpResult;
    public System.Action&lt;Packets.res_nasGetUser> getGetUserResult;
    public System.Action&lt;int> getSignOutResult;

    // 싱글톤으로 만들어주자
    private void Awake()
    {
        HTTPManager.instance = this;

    }
    private void OnDestroy()
    {
        HTTPManager.instance = null;
    }

    // uri => /user/signup
    public void RequestSignup(string uri, Packets.req_nasSignUp packet)
    {
        StartCoroutine(this.RequestSignupImpl(uri, packet));
    }

    private IEnumerator RequestSignupImpl(string uri, Packets.req_nasSignUp packet)
    {
        
        var url = string.Format("{0}:{1}{2}", this.host, this.port, uri);
        Debug.Log(url);
        var www = new UnityWebRequest(url, "POST");
        //객체를 -> 문자열 직렬화 
        var json = JsonConvert.SerializeObject(packet);
        //문자열 -> byte배열로 직렬화 
        var rawdata = Encoding.UTF8.GetBytes(json);

        www.uploadHandler = new UploadHandlerRaw(rawdata);  //요청
        www.downloadHandler = new DownloadHandlerBuffer();  //응답 
        www.SetRequestHeader("Content-Type", "application/json");
        yield return www.SendWebRequest();
    
        if (www.result == UnityWebRequest.Result.Success)
        {
            Debug.LogFormat("--->{0}", www.downloadHandler.text);
            var res_signup = JsonConvert.DeserializeObject&lt;Packets.res_nasSignUp>(www.downloadHandler.text);    //역직렬화 
            Debug.LogFormat("status : {0}", res_signup.statusCode);
            this.getSignUpResult(res_signup.statusCode);
        }
        else
        {

            this.getSignUpResult(500);
            Debug.LogFormat("에러");
        }

        www.Dispose();
    }

    public void RequestGetUser(string uri, Packets.req_nasGetUser packet)
    {
        StartCoroutine(this.RequestGetUserImpl(uri, packet));
    }

    private IEnumerator RequestGetUserImpl(string uri, Packets.req_nasGetUser packet)
    {

        var url = string.Format("{0}:{1}{2}", this.host, this.port, uri);
        Debug.Log(url);
        var www = new UnityWebRequest(url, "POST");
        //객체를 -> 문자열 직렬화 
        var json = JsonConvert.SerializeObject(packet);
        //문자열 -> byte배열로 직렬화 
        var rawdata = Encoding.UTF8.GetBytes(json);

        www.uploadHandler = new UploadHandlerRaw(rawdata);  //요청
        www.downloadHandler = new DownloadHandlerBuffer();  //응답 
        www.SetRequestHeader("Content-Type", "application/json");
        yield return www.SendWebRequest();

        if (www.result == UnityWebRequest.Result.Success)
        {
            Debug.LogFormat("--->{0}", www.downloadHandler.text);
            var res_getuser = JsonConvert.DeserializeObject&lt;Packets.res_nasGetUser>(www.downloadHandler.text);    //역직렬화 
            Debug.LogFormat("status : {0}, nickName : {1}", res_getuser.statusCode, res_getuser.nickname);
            this.getGetUserResult(res_getuser);
        }
        else
        {
            Packets.res_nasGetUser res_getuser = new Packets.res_nasGetUser();
            res_getuser.statusCode = 500;
            res_getuser.nickname = "";
            this.getGetUserResult(res_getuser);
            Debug.LogFormat("에러");
        }

        www.Dispose();
    }

    public void RequestSignOut(string uri, Packets.req_nasSignOut packet)
    {
        StartCoroutine(this.RequestSignOutImpl(uri, packet));
    }
    private IEnumerator RequestSignOutImpl(string uri, Packets.req_nasSignOut packet)
    {

        var url = string.Format("{0}:{1}{2}", this.host, this.port, uri);
        var www = new UnityWebRequest(url, "POST");
        //객체를 -> 문자열 직렬화 
        var json = JsonConvert.SerializeObject(packet);
        //문자열 -> byte배열로 직렬화 
        var rawdata = Encoding.UTF8.GetBytes(json);

        www.uploadHandler = new UploadHandlerRaw(rawdata);  //요청
        www.downloadHandler = new DownloadHandlerBuffer();  //응답 
        www.SetRequestHeader("Content-Type", "application/json");
        yield return www.SendWebRequest();

        if (www.result == UnityWebRequest.Result.Success)
        {
            Debug.LogFormat("--->{0}", www.downloadHandler.text);
            var res_signup = JsonConvert.DeserializeObject&lt;Packets.res_nasSignOut>(www.downloadHandler.text);    //역직렬화 
            Debug.LogFormat("status : {0}", res_signup.statusCode);
            this.getSignOutResult(res_signup.statusCode);
        }
        else
        {

            this.getSignOutResult(500);
            Debug.LogFormat("에러");
        }

        www.Dispose();
    }
}
</pre>



<div style="height:26px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">Packets.cs   &#8211; SignOut 추가 </p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Packets
{



    /*  유저 등록(/user/nasSignUp)
        statusCode
        200	유저 등록 완료
        201	이미 등록된 유저
        202	중복 닉네임
        500	서버 에러
    */


    public class req_nasSignUp
    {
        public string user_uid;
        public string nickname;
    }

    public class res_nasSignUp
    {
        public int statusCode;
    }




    /*  유저 검색 (/user/nasGetUser)
        statusCode
        200	유저 검색 완료
        201	등록 되지 않는 유저
        500	서버 에러
    */

    public class req_nasGetUser
    {
        public string user_uid;
    }

    public class res_nasGetUser
    {
        public int statusCode;
        public string nickname;
    }




    /*  유저 탈퇴 (/user/nasSignOut)
       statusCode
       200	유저 탈퇴 완료
       201	등록 되지 않는 유저
       500	서버 에러
   */

    public class req_nasSignOut
    {
        public string user_uid;
    }

    public class res_nasSignOut
    {
        public int statusCode;
    }



}</pre>



<div style="height:20px" aria-hidden="true" class="wp-block-spacer"></div>



<p class="has-medium-font-size">RestTestMain.cs   &#8211; SignOut 추가  </p>



<pre class="EnlighterJSRAW" data-enlighter-language="csharp" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;


public class RestTestMain : MonoBehaviour
{
    public Button SignUpTabBtn;
    public Button GetUserTabBtn;
    public Button SignOutTabBtn;

    public GameObject SignUpGO;
    public GameObject GetUserGO;
    public GameObject SignOutGO;

    public TMP_Text tmp_User_Uid;
    private string user_Uid;

    public TMP_InputField userNickName_IF;
    private string user_NickName;

    public TMP_InputField UserUid_IF;

    public Button sighUpBtn;
    public Button getUserBtn;

    public Button SignOutBtn;
    public TMP_InputField UserUid_IF_SignOut;

    public TMP_Text result_Text;


    void Start()
    {
        this.user_Uid = tmp_User_Uid.text;

        this.SignUpTabBtn.onClick.AddListener(() => {
            this.SignUpGO.SetActive(true);
            this.GetUserGO.SetActive(false);
            this.SignOutGO.SetActive(false);
        });

        this.GetUserTabBtn.onClick.AddListener(() => {
            this.SignUpGO.SetActive(false);
            this.GetUserGO.SetActive(true);
            this.SignOutGO.SetActive(false);
        });

        this.SignOutTabBtn.onClick.AddListener(() => {
            this.SignUpGO.SetActive(false);
            this.GetUserGO.SetActive(false);
            this.SignOutGO.SetActive(true);
        });


        HTTPManager.instance.getSignUpResult = (packet) =>
        {
            Debug.LogFormat("HTTPManager.instance.getSignUpResult : {0}", packet) ;
            switch (packet)
            {
                case 200:
                    this.result_Text.text = string.Format("status_code : {0}, 유저 등록 완료", packet);
                    break;
                case 201:
                    this.result_Text.text = string.Format("status_code : {0}, 이미 등록된 유저입니다.", packet);
                    break;
                case 202:
                    this.result_Text.text = string.Format("status_code : {0}, 중복된 닉네임 입니다.", packet);
                    break;
                case 500:
                    this.result_Text.text = string.Format("status_code : {0}, 서버가 응답이 없습니다.", packet);
                    break;
                default:
                    this.result_Text.text = string.Format("status_code : {0}, 이거 뜨면 망하는 겁니다.", packet);
                    break;
            }
        };


        HTTPManager.instance.getGetUserResult = (packet) => {

            switch (packet.statusCode)
            {
                case 200:
                    this.result_Text.text = string.Format("status_code : {0}, 유저 검색 완료\n", packet.statusCode);
                    this.result_Text.text += string.Format("NickName : {0}", packet.nickname);
                    break;
                case 201:
                    this.result_Text.text = string.Format("status_code : {0}, 서버에 등록되지 않은 유저입니다.", packet.statusCode);
                    break;
                case 500:
                    this.result_Text.text = string.Format("status_code : {0}, 서버가 응답이 없습니다.", packet.statusCode);
                    break;
                default:
                    this.result_Text.text = string.Format("status_code : {0}, 이거 뜨면 망하는 겁니다.", packet.statusCode);
                    break;
            }
        };

        HTTPManager.instance.getSignOutResult = (packet) => {

            switch (packet)
            {
                case 200:
                    this.result_Text.text = string.Format("status_code : {0}, 유저 탈퇴 완료", packet);
                    break;
                case 201:
                    this.result_Text.text = string.Format("status_code : {0}, 등록되지 않은 유저입니다.", packet);
                    break;
                case 500:
                    this.result_Text.text = string.Format("status_code : {0}, 서버가 응답이 없습니다.", packet);
                    break;
                default:
                    this.result_Text.text = string.Format("status_code : {0}, 이거 뜨면 망하는 겁니다.", packet);
                    break;
            }

        };




        this.sighUpBtn.onClick.AddListener(() =>
        {
            this.user_NickName = this.userNickName_IF.text;
            Debug.LogFormat("TMP_InputField : {0}", this.user_NickName);
            if (string.IsNullOrEmpty(this.user_NickName) &amp;&amp; string.IsNullOrEmpty(this.user_Uid))
            {
                this.result_Text.text = string.Format("닉네임을 입력해주세요.");
            }
            else
            {
                Debug.LogFormat("{0}, {1}", this.user_Uid, this.user_NickName);
                var packet = new Packets.req_nasSignUp()
                {
                    user_uid = this.user_Uid,
                    nickname = this.user_NickName
                };
                HTTPManager.instance.RequestSignup("/user/nasSignUp",packet);
            }
        });

        this.getUserBtn.onClick.AddListener(() => {

            if (string.IsNullOrEmpty(this.UserUid_IF.text))
            {
                this.result_Text.text = string.Format("유저의 UID를 입력해주세요.");
            }
            else
            {
                var packet = new Packets.req_nasGetUser()
                {
                    user_uid = this.UserUid_IF.text
                };
                HTTPManager.instance.RequestGetUser("/user/nasGetUser", packet);
            }


        });

        this.SignOutBtn.onClick.AddListener(() => {

            if (string.IsNullOrEmpty(this.UserUid_IF_SignOut.text))
            {
                this.result_Text.text = string.Format("유저의 UID를 입력해주세요.");
            }
            else
            {
                var packet = new Packets.req_nasSignOut()
                {
                    user_uid = this.UserUid_IF_SignOut.text
                };
                HTTPManager.instance.RequestSignOut("/user/nasSignOut", packet);
            }


        });

    }

    
}
</pre>



<div style="height:152px" aria-hidden="true" class="wp-block-spacer"></div>



<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5698326622209671"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-5698326622209671"
     data-ad-slot="5078714126"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>The post <a href="https://lycos7560.com/unity/restserver-unity-db%ec%97%b0%eb%8f%99/832/">RestServer + Unity DB연동</a> appeared first on <a href="https://lycos7560.com">어제와 내일의 나 그 사이의 이야기</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lycos7560.com/unity/restserver-unity-db%ec%97%b0%eb%8f%99/832/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
