Created
August 31, 2011 16:13
-
-
Save mumoshu/1183918 to your computer and use it in GitHub Desktop.
Unity+WebSocket.cs
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
using UnityEngine; | |
using System.Collections; | |
using SuperWebSocket.Client; | |
using System; | |
public class Net : MonoBehaviour { | |
private string lastMessage = string.Empty; | |
public static string serverURI = "ws://192.168.100.196:12345/channels/0?userId=1"; | |
public static WebSocket webSocket = new WebSocket(serverURI, "basic"); | |
void Awake () { | |
Debug.Log("Awoke!"); | |
webSocket.OnClose += new EventHandler(webSocketClient_OnClose); | |
webSocket.OnOpen += new EventHandler(webSocketClient_OnOpen); | |
webSocket.OnMessage += new EventHandler<MessageEventArgs>(webSocketClient_OnMessage); | |
webSocket.Connect(); | |
} | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
void OnDestroy () { | |
Debug.Log("Destroy!"); | |
webSocket.Close(); | |
} | |
void webSocketClient_OnOpen(object sender, EventArgs e) | |
{ | |
Debug.Log("OnOpen!"); | |
webSocket.Send("say:Hello WebSocket from Unity!"); | |
} | |
void webSocketClient_OnMessage(object sender, MessageEventArgs e) | |
{ | |
lastMessage = e.Message; | |
Debug.Log("lastMessage = " + lastMessage); | |
} | |
void webSocketClient_OnClose(object sender, EventArgs e) | |
{ | |
Debug.Log("OnClose!"); | |
} | |
} |
The code is a bit old. The websocket client had been separated from SuperWebSocket.Client to the new client project WebSocket4Net long days ago.
Hi, how can i download a file with websockets from a URL and save the file in specific location for example : DOWNLOADS. in Unity. Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SuperWebSocket is a .net implementation of WebSocket SERVER. http://superwebsocket.codeplex.com/
CLIENT implementation is WebSocket4Net. http://websocket4net.codeplex.com/