Browse Source

修改测试逻辑,改为直接开启http服务器

master
DESKTOP-B25GA9E\W35 2 years ago
parent
commit
8658c36f10
  1. 309
      Assets/MsgTransmitTools/Example/Scenes/HttpServerExample.unity
  2. 0
      Assets/MsgTransmitTools/Example/Scenes/HttpServerExample.unity.meta
  3. 9
      Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerModel.cs
  4. 12
      Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs

309
Assets/MsgTransmitTools/Example/Scenes/ServerExample.unity → Assets/MsgTransmitTools/Example/Scenes/HttpServerExample.unity

@ -204,84 +204,6 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &846447147
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 846447148}
- component: {fileID: 846447150}
- component: {fileID: 846447149}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &846447148
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 846447147}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2100516200}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &846447149
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 846447147}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Button
--- !u!222 &846447150
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 846447147}
m_CullTransparentMesh: 0
--- !u!1 &897822730 --- !u!1 &897822730
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -419,105 +341,6 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 2 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1253481797
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1253481801}
- component: {fileID: 1253481800}
- component: {fileID: 1253481799}
- component: {fileID: 1253481798}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1253481798
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1253481797}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1253481799
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1253481797}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &1253481800
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1253481797}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &1253481801
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1253481797}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 2100516200}
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!1 &1822805530 --- !u!1 &1822805530
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -582,135 +405,5 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 4 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &2100516199
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2100516200}
- component: {fileID: 2100516203}
- component: {fileID: 2100516202}
- component: {fileID: 2100516201}
m_Layer: 5
m_Name: Button
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2100516200
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2100516199}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 846447148}
m_Father: {fileID: 1253481801}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2100516201
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2100516199}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_SelectedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 2100516202}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1020834818}
m_MethodName: startServer
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &2100516202
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2100516199}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &2100516203
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2100516199}
m_CullTransparentMesh: 0

0
Assets/MsgTransmitTools/Example/Scenes/ServerExample.unity.meta → Assets/MsgTransmitTools/Example/Scenes/HttpServerExample.unity.meta

9
Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerModel.cs

@ -39,12 +39,16 @@ namespace JXSoft {
setLinkState((int)LinkStateDefault.Close); setLinkState((int)LinkStateDefault.Close);
return base.Close(); return base.Close();
} }
public void setPrefixes(string[] prefixes) {
this.GetUtility<HttpServerUtility>().address = prefixes;
}
} }
public class HttpServerUtility:IUtility public class HttpServerUtility:IUtility
{ {
//example:http://127.0.0.1:8080/index //example:http://127.0.0.1:8080/index
public string address; public string[] address;
public HttpListener httpServer; public HttpListener httpServer;
public bool isReceivedValue = false; public bool isReceivedValue = false;
@ -88,8 +92,7 @@ namespace JXSoft {
} }
public bool startServer() public bool startServer()
{ {
string[] prefixes = { address }; bool isSuccess = startServer(address);
bool isSuccess = startServer(prefixes);
return isSuccess; return isSuccess;
} }
#endregion #endregion

12
Assets/MsgTransmitTools/ExtendLinkModel/HttpServer/HttpServerView.cs

@ -19,37 +19,37 @@ namespace JXSoft {
public class HttpServerView : MonoBehaviour,IController public class HttpServerView : MonoBehaviour,IController
{ {
public string[] prefixes; public string[] prefixes;
public HttpServerUtility httpServer;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
//Debug.Log(int.Parse("AA",System.Globalization.NumberStyles.HexNumber).ToString()); //Debug.Log(int.Parse("AA",System.Globalization.NumberStyles.HexNumber).ToString());
this.httpServer = this.GetUtility<HttpServerUtility>();
this.RegisterMessageEvent<DYData.BluetoothGatewayData>(e => { this.RegisterMessageEvent<DYData.BluetoothGatewayData>(e => {
Debug.Log("收到消息:"+e.ip); Debug.Log("收到消息:"+e.ip);
}).UnRegisterWhenGameObjectDestroyed(gameObject); }).UnRegisterWhenGameObjectDestroyed(gameObject);
this.GetModel<HttpServerModel>().onReceive<DYData.BluetoothGatewayData>(); this.GetModel<HttpServerModel>().onReceive<DYData.BluetoothGatewayData>();
startServer();
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if (httpServer != null && !"".Equals(httpServer.getReceivedValue())) if (this.GetUtility<HttpServerUtility>().httpServer != null && !"".Equals(this.GetUtility<HttpServerUtility>().getReceivedValue()))
{ {
/*GameObject item = Instantiate(tcpMsgItem, tcpMsgContent); /*GameObject item = Instantiate(tcpMsgItem, tcpMsgContent);
item.GetComponentInChildren<Text>().text = tcpUtil.receivedData; item.GetComponentInChildren<Text>().text = tcpUtil.receivedData;
this.GetModel<TCPClientModel>().onDataRecived.Invoke(tcpUtil.receivedData); this.GetModel<TCPClientModel>().onDataRecived.Invoke(tcpUtil.receivedData);
*/ */
this.GetModel<HttpServerModel>().onDataRecived.Invoke(httpServer.receivedData); this.GetModel<HttpServerModel>().onDataRecived.Invoke(this.GetUtility<HttpServerUtility>().receivedData);
} }
} }
public void startServer() { public void startServer() {
bool isSuccess = httpServer.startServer(prefixes); this.GetModel<HttpServerModel>().setPrefixes(prefixes);
bool isSuccess = this.GetModel<HttpServerModel>().Start();
Debug.Log("ServerOpen:"+isSuccess); Debug.Log("ServerOpen:"+isSuccess);
} }
private void OnDestroy() private void OnDestroy()
{ {
httpServer.closeServer(); this.GetModel<HttpServerModel>().Close();
} }
public IArchitecture GetArchitecture() public IArchitecture GetArchitecture()

Loading…
Cancel
Save