├── bin
├── libudpkit_ios.a
├── libudpkit_android.so
└── libudpkit_win32.dll
├── proj
├── android
│ ├── libs
│ │ └── android-support-v4.jar
│ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-v11
│ │ │ └── styles.xml
│ │ └── values-v14
│ │ │ └── styles.xml
│ ├── .settings
│ │ └── org.eclipse.jdt.core.prefs
│ ├── gen
│ │ └── fholm
│ │ │ └── udpkit
│ │ │ └── nativeandroid
│ │ │ ├── BuildConfig.java
│ │ │ └── R.java
│ ├── jni
│ │ └── Android.mk
│ ├── .classpath
│ ├── AndroidManifest.xml
│ ├── project.properties
│ └── .project
├── ios
│ └── udpkit_ios.xcodeproj
│ │ ├── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ └── fredrik.xcuserdatad
│ │ └── xcschemes
│ │ ├── xcschememanagement.plist
│ │ └── udpkit_ios.xcscheme
├── win32
│ ├── libudpkit_win32.sln
│ ├── libudpkit_win32.vcxproj.filters
│ └── libudpkit_win32.vcxproj
└── managed
│ ├── udpkit.unity.csproj
│ ├── udpkit.platform.managed.csproj
│ ├── udpkit.platform.ios.csproj
│ ├── udpkit.platform.android.csproj
│ ├── udpkit.dev.csproj
│ ├── udpkit.platform.win32.csproj
│ ├── udpkit.examples.chat.csproj
│ ├── udpkit.examples.simple.csproj
│ ├── udpkit.stresstest.csproj
│ └── udpkit.csproj
├── src
├── udpkit.examples.unity
│ ├── Assets
│ │ ├── Scene.unity
│ │ ├── Scene.unity.meta
│ │ ├── Plugins.meta
│ │ ├── Plugins
│ │ │ ├── iOS
│ │ │ │ └── libudpkit_ios.a
│ │ │ ├── iOS.meta
│ │ │ ├── Android.meta
│ │ │ ├── Android
│ │ │ │ ├── libudpkit_android.so.meta
│ │ │ │ └── libudpkit_android.so
│ │ │ ├── udpUnityUtils.cs.meta
│ │ │ └── udpUnityUtils.cs
│ │ ├── demoGUI.cs.meta
│ │ ├── demoPeer.cs.meta
│ │ ├── demoSerializer.cs.meta
│ │ ├── demoSerializer.cs
│ │ ├── demoGUI.cs
│ │ └── demoPeer.cs
│ └── ProjectSettings
│ │ ├── AudioManager.asset
│ │ ├── InputManager.asset
│ │ ├── TagManager.asset
│ │ ├── TimeManager.asset
│ │ ├── EditorSettings.asset
│ │ ├── NavMeshLayers.asset
│ │ ├── NetworkManager.asset
│ │ ├── DynamicsManager.asset
│ │ ├── GraphicsSettings.asset
│ │ ├── Physics2DSettings.asset
│ │ ├── ProjectSettings.asset
│ │ ├── QualitySettings.asset
│ │ └── EditorBuildSettings.asset
├── udpkit.dev
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── main.cs
├── udpkit.stresstest
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── udpSequenceGenerator.cs
│ ├── udpRecvChannel.cs
│ ├── udpSendChannel.cs
│ └── Program.cs
├── udpkit.examples.chat
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── Program.cs
├── udpkit.examples.simple
│ ├── App.config
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── Program.cs
├── udpkit
│ ├── udpPrecisionTimer.cs
│ ├── udpSendHandle.cs
│ ├── udpCommand.cs
│ ├── udpException.cs
│ ├── udpUtils.cs
│ ├── udpConnectionStats.cs
│ ├── udpPlatform.cs
│ ├── udpSocketMultiplexer.cs
│ ├── udpAssert.cs
│ ├── udpSet.cs
│ ├── udpRingBuffer.cs
│ ├── udpSerializer.cs
│ ├── udpHeader.cs
│ ├── udpEndpoint.cs
│ ├── udpAddress.cs
│ ├── udpMath.cs
│ ├── udpLog.cs
│ ├── udpByteConverter.cs
│ ├── udpEvent.cs
│ └── udpConfig.cs
├── AssemblyInfo.cs
├── udpkit.lib
│ ├── timers.h
│ ├── common.cpp
│ ├── timers.cpp
│ ├── socket.h
│ ├── common.h
│ └── socket.cpp
├── udpkit.platform.managed
│ ├── udpPrecisionTimer.cs
│ └── udpPlatformManaged.cs
├── udpkit.platform.native
│ ├── udpNativeInvoke.cs
│ └── udpPlatformNative.cs
└── slimmath
│ └── half.cs
├── .gitignore
├── license.txt
├── readme.txt
└── .gitattributes
/bin/libudpkit_ios.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/bin/libudpkit_ios.a
--------------------------------------------------------------------------------
/bin/libudpkit_android.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/bin/libudpkit_android.so
--------------------------------------------------------------------------------
/bin/libudpkit_win32.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/bin/libudpkit_win32.dll
--------------------------------------------------------------------------------
/proj/android/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/proj/android/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proj/android/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | udpkit.nativeAndroid
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Scene.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/Assets/Scene.unity
--------------------------------------------------------------------------------
/proj/android/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/proj/android/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/proj/android/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/proj/android/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/proj/android/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/proj/android/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Scene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1b1a4947fa21b294fa81217bbb3530ba
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Plugins.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 533ea146ea42f174497fed515e1fe915
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Plugins/iOS/libudpkit_ios.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/Assets/Plugins/iOS/libudpkit_ios.a
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Plugins/iOS.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9145911a2083dfb4885e726cad0deafa
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/EditorSettings.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/NavMeshLayers.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/NavMeshLayers.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Plugins/Android.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: be645715ece3c0e44bf320ea13c53233
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Plugins/Android/libudpkit_android.so.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f92d336c7da2c7c4284eebb942952fb7
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/GraphicsSettings.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/Physics2DSettings.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/ProjectSettings.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Plugins/Android/libudpkit_android.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tanhaiwang/udpkit/HEAD/src/udpkit.examples.unity/Assets/Plugins/Android/libudpkit_android.so
--------------------------------------------------------------------------------
/src/udpkit.dev/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/udpkit.stresstest/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/udpkit.examples.chat/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/udpkit.examples.simple/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/proj/android/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/proj/android/gen/fholm/udpkit/nativeandroid/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package fholm.udpkit.nativeandroid;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/proj/ios/udpkit_ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/demoGUI.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7d076d2a770cd0f42950a7ab8a43b228
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/demoPeer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: cae2093199fb7f9409d0532c1a5f0b88
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/demoSerializer.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 0c11bc30f61a8624fa51deaa703b870d
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Plugins/udpUnityUtils.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 986c3cf193970e043964d43f55979b92
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/proj/android/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 | include $(CLEAR_VARS)
3 | LOCAL_LDLIBS := -llog
4 | LOCAL_MODULE := udpkit_android
5 | LOCAL_SRC_FILES := ../../../src/udpkit.lib/common.cpp ../../../src/udpkit.lib/socket.cpp ../../../src/udpkit.lib/timers.cpp
6 | include $(BUILD_SHARED_LIBRARY)
--------------------------------------------------------------------------------
/proj/android/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/demoSerializer.cs:
--------------------------------------------------------------------------------
1 | using UdpKit;
2 |
3 | public class demoSerializer : UdpSerializer {
4 | public override bool Pack (ref UdpBitStream stream, ref object o) {
5 | throw new System.NotImplementedException();
6 | }
7 |
8 | public override bool Unpack (ref UdpBitStream stream, ref object o) {
9 | throw new System.NotImplementedException();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/proj/android/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/proj/android/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/udpkit/udpPrecisionTimer.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 |
3 | namespace udpkit {
4 | class udpPrecisionTimer {
5 | static readonly long start = Stopwatch.GetTimestamp();
6 | static readonly double freq = 1.0 / (double) Stopwatch.Frequency;
7 |
8 | internal static uint getCurrentTime () {
9 | long diff = Stopwatch.GetTimestamp() - start;
10 | double seconds = (double) diff * freq;
11 | return (uint) (seconds * 1000.0);
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.suo
2 | obj
3 | bin
4 | *.userprefs
5 | *tlog*
6 | *.log
7 | *.obj
8 | *.idb
9 | *.pdb
10 | *.user
11 | *.sdf
12 | *.opensdf
13 | *.exp
14 | *.ilk
15 | *.lib
16 | *.dll
17 | *.pidb
18 | *.dll.meta
19 | *.a
20 | *.a.meta
21 | *swp
22 | *.so
23 | *.xcuserstate
24 | *.xckptlist
25 | *.xccheckout
26 | src/udpkit.examples.unity/*_Data/*
27 | src/udpkit.examples.unity/*.exe
28 | src/udpkit.examples.unity/Library
29 | src/udpkit.examples.unity/Temp
30 | src/udpkit.examples.unity/*.sln
31 | src/udpkit.examples.unity/*.csproj
32 |
--------------------------------------------------------------------------------
/proj/android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/proj/android/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 | android.library=true
16 |
--------------------------------------------------------------------------------
/proj/ios/udpkit_ios.xcodeproj/xcuserdata/fredrik.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | udpkit_ios.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 35D9975C184F59E6008F33D2
16 |
17 | primary
18 |
19 |
20 | 35D9976C184F59E6008F33D2
21 |
22 | primary
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/proj/android/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/demoGUI.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public class demoGUI : MonoBehaviour {
4 |
5 | void OnGUI () {
6 | float w = Screen.width;
7 | float h = Screen.height;
8 | float buttonHeight = h * 0.2f;
9 | float buttonWidth = w * 0.35f;
10 | float buttonMarginLR = w * 0.1f;
11 | float buttonMarginTB = h * 0.4f;
12 |
13 | if (GUI.Button(new Rect(buttonMarginLR, buttonMarginTB, buttonWidth, buttonHeight), "Server")) {
14 | gameObject.AddComponent().isServer = true;
15 | }
16 |
17 | if (GUI.Button(new Rect(buttonMarginLR + buttonWidth + buttonMarginLR, buttonMarginTB, buttonWidth, buttonHeight), "Client")) {
18 | gameObject.AddComponent().isServer = false;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/Plugins/udpUnityUtils.cs:
--------------------------------------------------------------------------------
1 | using UdpKit;
2 |
3 | public static class UdpKitUnityUtils {
4 | public static UdpSocket CreatePlatformSpecificSocket () where TSerializer : UdpSerializer, new() {
5 | return CreatePlatformSpecificSocket(new UdpConfig());
6 | }
7 |
8 | public static UdpSocket CreatePlatformSpecificSocket (UdpConfig config) where TSerializer : UdpSerializer, new() {
9 | #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
10 | return UdpSocket.Create(config);
11 | #elif UNITY_IPHONE
12 | return UdpSocket.Create(config);
13 | #elif UNITY_ANDROID
14 | return UdpSocket.Create(config);
15 | #else
16 | throw new System.NotImplementedException ("UdpKit doesn't support the current platform");
17 | #endif
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/proj/android/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | udpkit.nativeAndroid
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/proj/win32/libudpkit_win32.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libudpkit_win32", "libudpkit_win32.vcxproj", "{085D3B6D-76D2-4DCD-879C-257B170FBEC5}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Release|Win32 = Release|Win32
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {085D3B6D-76D2-4DCD-879C-257B170FBEC5}.Debug|Win32.ActiveCfg = Debug|Win32
15 | {085D3B6D-76D2-4DCD-879C-257B170FBEC5}.Debug|Win32.Build.0 = Debug|Win32
16 | {085D3B6D-76D2-4DCD-879C-257B170FBEC5}.Release|Win32.ActiveCfg = Release|Win32
17 | {085D3B6D-76D2-4DCD-879C-257B170FBEC5}.Release|Win32.Build.0 = Release|Win32
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/src/udpkit.examples.unity/Assets/demoPeer.cs:
--------------------------------------------------------------------------------
1 | using UdpKit;
2 | using UnityEngine;
3 |
4 | public class demoPeer : MonoBehaviour {
5 | UdpSocket socket;
6 |
7 | [HideInInspector]
8 | internal bool isServer;
9 |
10 | [HideInInspector]
11 | internal string serverAddress = "127.0.0.1:14000";
12 |
13 | void Awake () {
14 | UdpLog.SetWriter(s => Debug.Log(s));
15 | }
16 |
17 | void Start () {
18 | socket = UdpKitUnityUtils.CreatePlatformSpecificSocket();
19 |
20 | if (isServer) {
21 | socket.Start(new UdpEndPoint(serverAddress));
22 | } else {
23 | socket.Start(UdpEndPoint.Any);
24 | socket.Connect(new UdpEndPoint(serverAddress));
25 | }
26 | }
27 |
28 | void OnDestroy () {
29 | socket.Close();
30 | }
31 |
32 | void Update () {
33 | UdpEvent ev = default(UdpEvent);
34 |
35 | while (socket.Poll(ref ev)) {
36 | switch (ev.EventType) {
37 | case UdpEventType.Connected:
38 | UdpLog.User("Client connect from {0}", ev.Connection.RemoteEndPoint);
39 | break;
40 | }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | #if UDPKIT_DLL_UDPKIT
6 | [assembly: AssemblyTitle("udpkit")]
7 | [assembly: AssemblyProduct("udpkit")]
8 | #elif UDPKIT_DLL_PLATFORM_ANDROID
9 | [assembly: AssemblyTitle("udpkit.platform.android")]
10 | [assembly: AssemblyProduct("udpkit.platform.android")]
11 | #elif UDPKIT_DLL_PLATFORM_IOS
12 | [assembly: AssemblyTitle("udpkit.platform.ios")]
13 | [assembly: AssemblyProduct("udpkit.platform.ios")]
14 | #elif UDPKIT_DLL_PLATFORM_WIN32
15 | [assembly: AssemblyTitle("udpkit.platform.win32")]
16 | [assembly: AssemblyProduct("udpkit.platform.win32")]
17 | #elif UDPKIT_DLL_PLATFORM_MANAGED
18 | [assembly: AssemblyTitle("udpkit.platform.managed")]
19 | [assembly: AssemblyProduct("udpkit.platform.managed")]
20 | #elif UDPKIT_DLL_UNITY
21 | [assembly: AssemblyTitle("udpkit.unity")]
22 | [assembly: AssemblyProduct("udpkit.unity")]
23 | #endif
24 |
25 | [assembly: AssemblyDescription(".Net/Mono/Unity networking library for games")]
26 | [assembly: AssemblyConfiguration("")]
27 | [assembly: AssemblyCompany("")]
28 | [assembly: AssemblyCopyright("Copyright © 2012-2013 Fredrik Holmstrom")]
29 | [assembly: AssemblyTrademark("")]
30 | [assembly: AssemblyCulture("")]
31 | [assembly: ComVisible(false)]
32 | [assembly: AssemblyVersion("0.1.0.0")]
33 | [assembly: AssemblyFileVersion("0.1.0.0")]
34 |
--------------------------------------------------------------------------------
/src/udpkit.lib/timers.h:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #include "common.h"
26 | #include
27 |
28 | #ifdef UDPKIT_IOS
29 | #include
30 | #endif
31 |
32 | #ifndef UDPKIT_WIN
33 | EXPORT_API U32 udpGetHighPrecisionTime();
34 | #endif
35 |
--------------------------------------------------------------------------------
/src/udpkit/udpSendHandle.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | namespace UdpKit {
26 | struct UdpHandle {
27 | public uint SendTime;
28 | public ushort ObjSequence;
29 | public bool IsObject;
30 | public object Object;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/udpkit/udpCommand.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | namespace UdpKit {
26 | internal enum UdpCommandType : byte {
27 | Connect = 2,
28 | Accepted = 4,
29 | Refused = 6,
30 | Disconnected = 8,
31 | Ping = 10,
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/udpkit.dev/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("udpkitdev")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("udpkitdev")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("06be3e38-9839-4281-b1d2-b996e866564b")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/udpkit.stresstest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("udpkit.stresstest")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("udpkit.stresstest")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("cf1f9691-e683-4bf8-a1a1-f6bb190e02e6")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/udpkit.examples.chat/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("udpkit.examples.complete")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("udpkit.examples.complete")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("06964735-49d3-49ce-bd95-1e7411192d78")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/udpkit.examples.simple/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("udpkit.examples.simple")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("udpkit.examples.simple")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("47576deb-2282-493c-a582-b8cb00215a32")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/udpkit/udpException.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | using System;
26 |
27 | namespace UdpKit {
28 | public class UdpException : Exception {
29 | internal UdpException () : base() { }
30 | internal UdpException (string msg) : base(msg) { }
31 | internal UdpException (string fmt, params object[] args) : this(string.Format(fmt, args)) { }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/proj/win32/libudpkit_win32.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 |
29 |
30 | Source Files
31 |
32 |
33 | Source Files
34 |
35 |
36 | Source Files
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/udpkit/udpUtils.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | using System;
26 | using System.Diagnostics;
27 | using System.Threading;
28 |
29 | namespace UdpKit {
30 | internal static class UdpUtils {
31 | /*
32 | public static int enumToInt (T value) where T : struct {
33 | throw new NotImplementedException();
34 | }
35 |
36 | public static T intToEnum (int value) where T : struct {
37 | throw new NotImplementedException();
38 | }
39 | */
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/proj/android/gen/fholm/udpkit/nativeandroid/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package fholm.udpkit.nativeandroid;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static int ic_launcher=0x7f020000;
15 | }
16 | public static final class string {
17 | public static int app_name=0x7f030000;
18 | }
19 | public static final class style {
20 | /**
21 | Base application theme, dependent on API level. This theme is replaced
22 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
23 |
24 |
25 | Theme customizations available in newer API levels can go in
26 | res/values-vXX/styles.xml, while customizations related to
27 | backward-compatibility can go here.
28 |
29 |
30 | Base application theme for API 11+. This theme completely replaces
31 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
32 |
33 | API 11 theme customizations can go here.
34 |
35 | Base application theme for API 14+. This theme completely replaces
36 | AppBaseTheme from BOTH res/values/styles.xml and
37 | res/values-v11/styles.xml on API 14+ devices.
38 |
39 | API 14 theme customizations can go here.
40 | */
41 | public static int AppBaseTheme=0x7f040000;
42 | /** Application theme.
43 | All customizations that are NOT specific to a particular API-level can go here.
44 | */
45 | public static int AppTheme=0x7f040001;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/udpkit.platform.managed/udpPrecisionTimer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | using System.Diagnostics;
26 |
27 | namespace UdpKit {
28 | class UdpPrecisionTimer {
29 | static readonly long start = Stopwatch.GetTimestamp();
30 | static readonly double freq = 1.0 / (double) Stopwatch.Frequency;
31 |
32 | internal static uint GetCurrentTime () {
33 | long diff = Stopwatch.GetTimestamp() - start;
34 | double seconds = (double) diff * freq;
35 | return (uint) (seconds * 1000.0);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/udpkit.lib/common.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #include "common.h"
26 |
27 | EXPORT_API const char* udpPlatform() {
28 | #ifdef UDPKIT_WIN32
29 | return "win32";
30 | #elif UDPKIT_WIN64
31 | return "win64";
32 | #elif UDPKIT_IOS_SIMULATOR
33 | return "ios_simulator";
34 | #elif UDPKIT_IOS
35 | return "ios";
36 | #elif UDPKIT_OSX
37 | return "osx";
38 | #elif UDPKIT_ANDROID
39 | return "android";
40 | #elif UDPKIT_LINUX
41 | return "linux";
42 | #else
43 | return "unknown";
44 | #endif
45 | }
46 |
47 | EXPORT_API const char* udpPlatformErrorString(int errorCode) {
48 | return strerror(errorCode);
49 | }
--------------------------------------------------------------------------------
/src/udpkit.stresstest/udpSequenceGenerator.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | namespace UdpKit.stresstest {
26 | struct udpSequenceGenerator {
27 | uint mask;
28 | uint sequence;
29 |
30 | public udpSequenceGenerator (int bits)
31 | : this(bits, 0u) {
32 | }
33 |
34 | public udpSequenceGenerator (int bits, uint start) {
35 | mask = (1u << bits) - 1u;
36 | sequence = start & mask;
37 | }
38 |
39 | public uint next () {
40 | sequence += 1u;
41 | sequence &= mask;
42 | return sequence;
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/src/udpkit/udpConnectionStats.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | namespace UdpKit {
26 | public struct UdpConnectionStats {
27 | public uint BytesSent;
28 | public uint BytesReceived;
29 | public uint PacketsSent;
30 | public uint PacketsLost;
31 | public uint PacketsDelivered;
32 | public uint PacketsReceived;
33 | public uint CommandSent;
34 | public uint CommandsReceived;
35 |
36 | internal void PacketReceived () {
37 | PacketsReceived += 1;
38 | }
39 |
40 | internal void PacketSent () {
41 | PacketsSent += 1;
42 | }
43 |
44 | internal void PacketLost () {
45 | PacketsLost += 1;
46 | }
47 |
48 | internal void PacketDelivered () {
49 | PacketsDelivered += 1;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/udpkit/udpPlatform.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | namespace UdpKit {
26 | public enum UdpSocketInterfaceError {
27 | None = 0,
28 | Unknown = 1,
29 | WouldBlock = 2
30 | }
31 |
32 | public abstract class UdpPlatform {
33 | public abstract UdpSocketInterfaceError Error { get; }
34 | public abstract UdpEndPoint EndPoint { get; }
35 | public abstract long PlatformError { get; }
36 | public abstract string PlatformErrorString { get; }
37 | public abstract uint PlatformPrecisionTime { get; }
38 | public abstract bool Close ();
39 | public abstract bool Bind (UdpEndPoint endpoing);
40 | public abstract bool RecvPoll (int timeoutInMs);
41 | public abstract bool RecvFrom (byte[] buffer, int bufferSize, ref int bytesReceived, ref UdpEndPoint remoteEndpoint);
42 | public abstract bool SendTo (byte[] buffer, int bytesToSend, UdpEndPoint endpoint, ref int bytesSent);
43 | }
44 | }
--------------------------------------------------------------------------------
/src/udpkit/udpSocketMultiplexer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | using System;
26 | using System.Collections.Generic;
27 | using System.Threading;
28 |
29 | namespace UdpKit {
30 | public class UdpSocketMultiplexer {
31 |
32 | int index;
33 | UdpSocket[] sockets;
34 |
35 | internal UdpSocketMultiplexer (params UdpSocket[] sockets) {
36 | this.index = 0;
37 | this.sockets = sockets;
38 | }
39 |
40 | public bool Poll (ref UdpEvent ev) {
41 | bool allowRestart = true;
42 |
43 | RESTART:
44 | for (int i = index; i < sockets.Length; ++i) {
45 | if (sockets[i].Poll(ref ev)) {
46 | index = i + 1;
47 | return true;
48 | }
49 | }
50 |
51 | if (allowRestart) {
52 | index = 0;
53 | allowRestart = false;
54 | goto RESTART;
55 | }
56 |
57 | return false;
58 | }
59 |
60 | }
61 |
62 | }
--------------------------------------------------------------------------------
/src/udpkit.lib/timers.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | #include "timers.h"
26 |
27 | #ifdef UDPKIT_ANDROID
28 | EXPORT_API U32 udpGetHighPrecisionTime()
29 | {
30 | timespec spec = timespec();
31 | clock_gettime(CLOCK_MONOTONIC, &spec);
32 |
33 | return (spec.tv_sec * 1000) + (spec.tv_nsec / 1000 / 1000);
34 | }
35 | #elif UDPKIT_IOS
36 |
37 | double mach_clock()
38 | {
39 | static bool init = 0;
40 | static mach_timebase_info_data_t tbInfo;
41 | static double conversionFactor;
42 |
43 | if (!init)
44 | {
45 | init = 1 ;
46 | mach_timebase_info(&tbInfo);
47 | conversionFactor = tbInfo.numer / (1e9 * tbInfo.denom);
48 | }
49 |
50 | return mach_absolute_time() * conversionFactor;
51 | }
52 |
53 | double mach_clock_diff()
54 | {
55 | static double lastTime = 0;
56 | double currentTime = mach_clock();
57 | double diff = currentTime - lastTime;
58 | lastTime = currentTime;
59 | return diff;
60 | }
61 |
62 | EXPORT_API U32 udpGetHighPrecisionTime()
63 | {
64 | return (U32) (mach_clock_diff() * 1000.0);
65 | }
66 | #endif
--------------------------------------------------------------------------------
/src/udpkit/udpAssert.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | using System;
26 | using System.Diagnostics;
27 | using System.Threading;
28 |
29 | namespace UdpKit {
30 | static class UdpAssert {
31 | [Conditional("DEBUG")]
32 | internal static void Assert (bool condition) {
33 | if (!condition)
34 | throw new UdpException("assert failed");
35 | }
36 |
37 | [Conditional("DEBUG")]
38 | internal static void Assert (bool condition, string message) {
39 | if (!condition)
40 | throw new UdpException(String.Concat("assert failed: ", message));
41 | }
42 |
43 | [Conditional("DEBUG")]
44 | internal static void Assert (bool condition, string message, params object[] args) {
45 | if (!condition)
46 | throw new UdpException(String.Concat("assert failed: ", String.Format(message, args)));
47 | }
48 |
49 | [Conditional("DEBUG")]
50 | internal static void AssertThread (Thread thread) {
51 | Assert(ReferenceEquals(Thread.CurrentThread, thread), "expected thread to be '{0}', but was '{1}'", thread.Name, Thread.CurrentThread.Name);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/udpkit/udpSet.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | using System.Collections.Generic;
26 |
27 | namespace UdpKit {
28 | class UdpSet {
29 | public int Count {
30 | get { return set.Count; }
31 | }
32 |
33 | public bool Remove (T value) {
34 | return set.Remove(value);
35 | }
36 |
37 | #if HAS_HASHSET
38 | readonly HashSet set;
39 |
40 | public UdpSet (IEqualityComparer comparer) {
41 | set = new HashSet(comparer);
42 | }
43 |
44 | public bool Add (T value) {
45 | return set.Add(value);
46 | }
47 |
48 | public bool Contains (T value) {
49 | return set.Contains(value);
50 | }
51 | #else
52 | readonly Dictionary set;
53 |
54 | public UdpSet (IEqualityComparer comparer) {
55 | set = new Dictionary(comparer);
56 | }
57 |
58 | public bool Add (T value) {
59 | if (set.ContainsKey(value))
60 | return false;
61 |
62 | set.Add(value, null);
63 | return true;
64 | }
65 |
66 | public bool Contains (T value) {
67 | return set.ContainsKey(value);
68 | }
69 | #endif
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/udpkit/udpRingBuffer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | namespace UdpKit {
26 | class UdpRingBuffer where T : struct {
27 | int head;
28 | int tail;
29 | int count;
30 |
31 | readonly T[] array;
32 |
33 | public bool Full {
34 | get { return count == array.Length; }
35 | }
36 |
37 | public bool Empty {
38 | get { return count == 0; }
39 | }
40 |
41 | public float FillRatio {
42 | get { return UdpMath.Clamp((float) count / (float) array.Length, 0f, 1f); }
43 | }
44 |
45 | public UdpRingBuffer (int size) {
46 | array = new T[size];
47 | }
48 |
49 | public void Enqueue (T item) {
50 | if (count == array.Length)
51 | throw new UdpException("buffer is full");
52 |
53 | array[head] = item;
54 | head = (head + 1) % array.Length;
55 | count += 1;
56 | }
57 |
58 | public T Dequeue () {
59 | if (count == 0)
60 | throw new UdpException("buffer is empty");
61 |
62 | T item = array[tail];
63 | array[tail] = default(T);
64 | tail = (tail + 1) % array.Length;
65 | count -= 1;
66 | return item;
67 | }
68 |
69 | public T Peek () {
70 | if (count == 0)
71 | throw new UdpException("buffer is empty");
72 |
73 | return array[tail];
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/proj/ios/udpkit_ios.xcodeproj/xcuserdata/fredrik.xcuserdatad/xcschemes/udpkit_ios.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
52 |
53 |
54 |
55 |
61 |
62 |
64 |
65 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/src/udpkit/udpSerializer.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2012-2013 Fredrik Holmstrom (fredrik.johan.holmstrom@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in
14 | * all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | * THE SOFTWARE.
23 | */
24 |
25 | using System.Collections.Generic;
26 |
27 | namespace UdpKit {
28 | public delegate UdpSerializer UdpSerializerFactory ();
29 |
30 | public abstract class UdpSerializer {
31 | readonly Queue