Skip to content

Commit

Permalink
Fixed websocket already binded errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbelot committed Feb 10, 2022
1 parent dbd895a commit 2f043d4
Show file tree
Hide file tree
Showing 12 changed files with 534 additions and 104 deletions.
71 changes: 57 additions & 14 deletions Assets/Scenes/Main.unity

Large diffs are not rendered by default.

44 changes: 20 additions & 24 deletions Assets/Scripts/Network/WebsocketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,51 +49,47 @@ public class AugmentaService : WebSocketBehavior


private void Awake() {
activeManager = this;

if (!_isInitialized) {
Initialize();
CreateWebsocketServer();
}
}

private void OnDestroy() {
websocketServer.Stop();
}

void Initialize() {
activeManager = this;

CreateWebsocketServer();
_isInitialized = true;
}

// Start is called before the first frame update
void Start()
{


}

// Update is called once per frame
void Update()
{

if(_isInitialized)
websocketServer.Stop();
}

private void CreateWebsocketServer() {

if(_isInitialized) websocketServer.Stop();
if (_isInitialized) {
websocketServer.Stop();
_isInitialized = false;
}

websocketServer = new WebSocketServer(_wsServerPort);

websocketServer.AddWebSocketService<AugmentaService>("/");

websocketServer.Start();
try {
websocketServer.Start();
} catch (Exception e) {
Debug.LogError(e.Message);
return;
}

_websocketClient = new WebSocket("ws://127.0.0.1:"+_wsServerPort);
_websocketClient.Connect();

_isInitialized = true;
}

public void SendAugmentaMessage(String msg) {
_websocketClient.Send(_serverPrefix + msg);

if(_isInitialized)
_websocketClient.Send(_serverPrefix + msg);
}

#endregion
Expand Down
8 changes: 8 additions & 0 deletions Assets/StreamingAssets.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.ide.visualstudio": "2.0.2",
"com.unity.ide.vscode": "1.2.1",
"com.unity.postprocessing": "2.3.0",
"com.unity.textmeshpro": "3.0.1",
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.vscode": "1.2.5",
"com.unity.postprocessing": "3.2.0",
"com.unity.textmeshpro": "3.0.6",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
Expand Down
34 changes: 28 additions & 6 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,51 @@
"source": "builtin",
"dependencies": {}
},
"com.unity.ext.nunit": {
"version": "1.0.6",
"depth": 2,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.ide.visualstudio": {
"version": "2.0.2",
"version": "2.0.14",
"depth": 0,
"source": "registry",
"dependencies": {},
"dependencies": {
"com.unity.test-framework": "1.1.9"
},
"url": "https://packages.unity.com"
},
"com.unity.ide.vscode": {
"version": "1.2.1",
"version": "1.2.5",
"depth": 0,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.postprocessing": {
"version": "2.3.0",
"version": "3.2.0",
"depth": 0,
"source": "registry",
"dependencies": {},
"dependencies": {
"com.unity.modules.physics": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.29",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.ext.nunit": "1.0.6",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.textmeshpro": {
"version": "3.0.1",
"version": "3.0.6",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down
35 changes: 35 additions & 0 deletions ProjectSettings/MemorySettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!387306366 &1
MemorySettings:
m_ObjectHideFlags: 0
m_EditorMemorySettings:
m_MainAllocatorBlockSize: -1
m_ThreadAllocatorBlockSize: -1
m_MainGfxBlockSize: -1
m_ThreadGfxBlockSize: -1
m_CacheBlockSize: -1
m_TypetreeBlockSize: -1
m_ProfilerBlockSize: -1
m_ProfilerEditorBlockSize: -1
m_BucketAllocatorGranularity: -1
m_BucketAllocatorBucketsCount: -1
m_BucketAllocatorBlockSize: -1
m_BucketAllocatorBlockCount: -1
m_ProfilerBucketAllocatorGranularity: -1
m_ProfilerBucketAllocatorBucketsCount: -1
m_ProfilerBucketAllocatorBlockSize: -1
m_ProfilerBucketAllocatorBlockCount: -1
m_TempAllocatorSizeMain: -1
m_JobTempAllocatorBlockSize: -1
m_BackgroundJobTempAllocatorBlockSize: -1
m_JobTempAllocatorReducedBlockSize: -1
m_TempAllocatorSizeGIBakingWorker: -1
m_TempAllocatorSizeNavMeshWorker: -1
m_TempAllocatorSizeAudioWorker: -1
m_TempAllocatorSizeCloudWorker: -1
m_TempAllocatorSizeGfx: -1
m_TempAllocatorSizeJobWorker: -1
m_TempAllocatorSizeBackgroundWorker: -1
m_TempAllocatorSizePreloadManager: -1
m_PlatformMemorySettings: {}
43 changes: 43 additions & 0 deletions ProjectSettings/PackageManagerSettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 61
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_EnablePreviewPackages: 0
m_EnablePackageDependencies: 0
m_AdvancedSettingsExpanded: 1
m_ScopedRegistriesSettingsExpanded: 1
oneTimeWarningShown: 0
m_Registries:
- m_Id: main
m_Name:
m_Url: https://packages.unity.com
m_Scopes: []
m_IsDefault: 1
m_Capabilities: 7
m_UserSelectedRegistryName:
m_UserAddingNewScopedRegistry: 0
m_RegistryInfoDraft:
m_ErrorMessage:
m_Original:
m_Id:
m_Name:
m_Url:
m_Scopes: []
m_IsDefault: 0
m_Capabilities: 0
m_Modified: 0
m_Name:
m_Url:
m_Scopes:
-
m_SelectedScopeIndex: 0
Loading

0 comments on commit 2f043d4

Please sign in to comment.