-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
435 changed files
with
173,871 additions
and
5,193 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using UnityEngine; | ||
using WebSocketSharp; | ||
|
||
public class WebSocketClient | ||
{ | ||
WebSocketSharp.WebSocket m_ws; | ||
public string m_Message; | ||
bool m_isWSConnected = false; | ||
|
||
// Connect WebSocket | ||
void ConnectWS() | ||
{ | ||
if (m_isWSConnected) | ||
return; | ||
|
||
m_Message = "No data."; | ||
|
||
//using (m_ws = new WebSocket("ws://localhost:8080/")) | ||
using (m_ws = new WebSocket("ws://139.19.40.35:8080/")) | ||
{ | ||
//m_ws.Log.Level = WebSocketSharp.LogLevel.TRACE; | ||
//m_ws.Log.File = "D:\\ws_log.txt"; | ||
|
||
m_ws.OnOpen += (sender, e) => | ||
{ | ||
m_ws.Send(String.Format("Hello server.")); | ||
Debug.Log("Connection opened."); | ||
m_isWSConnected = true; | ||
}; | ||
m_ws.OnMessage += (sender, e) => | ||
{ | ||
m_Message = e.Data; | ||
//Debug.Log(m_Message); | ||
}; | ||
m_ws.OnClose += (sender, e) => | ||
{ | ||
m_ws.Connect(); // This is a hack, but whatever | ||
m_isWSConnected = false; | ||
}; | ||
m_ws.OnError += (sender, e) => | ||
{ | ||
// NOT PRINTING ERRORS | ||
//Debug.LogError(e.Message); | ||
m_isWSConnected = false; | ||
}; | ||
|
||
m_ws.Connect(); | ||
} | ||
} | ||
|
||
// Use this for initialization | ||
public void Start() | ||
{ | ||
ConnectWS(); | ||
} | ||
|
||
// Update is called once per frame | ||
public void Update() | ||
{ | ||
//Debug.Log(m_Message); | ||
//// Parse message | ||
//if (m_InputParser != null) | ||
// m_InputParser.parse(m_Message); | ||
} | ||
|
||
public void OnApplicationQuit() | ||
{ | ||
if (m_ws != null && m_ws.ReadyState == WebSocketState.OPEN) | ||
m_ws.Close(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.