Class NetworkMessenger
The network messenger for communication using TCP/UDP.
透過 TCP/UDP 溝通的網絡通訊器。
Inheritance
Namespace: Votanic.vNet.Messenger
Assembly: Votanic.vNet.dll
Syntax
[AddComponentMenu("")]
public class NetworkMessenger : MonoBehaviour
Fields
autoConnect
Auto start networking on start.
開始時自動連線。
Declaration
[Tooltip("Auto start networking on start.\n開始時自動連線。")]
public bool autoConnect
Field Value
| Type | Description |
|---|---|
| System.Boolean |
buffer
Time gap for checking connection state in seconds.
每次檢查連線狀態的時間緩衝(秒數)。
Declaration
[Tooltip("Time gap for checking connection state in seconds.\n每次檢查連線狀態的時間緩衝(秒數)。")]
public float buffer
Field Value
| Type | Description |
|---|---|
| System.Single |
checkConnection
Keeping send and receive data to check connection if true.
當 true 時不斷傳送及接收訊息以確認連線。
Declaration
[Tooltip("Keeping send and receive data to check connection.\n不斷傳送及接收訊息以確認連線。")]
public bool checkConnection
Field Value
| Type | Description |
|---|---|
| System.Boolean |
data
All received data.
所有已接收的數據。
Declaration
[Tooltip("All received data.\n所有已接收的數據。")]
public List<string> data
Field Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.String> |
errorMsg
Error message list.
錯誤訊息列表。
Declaration
[Tooltip("Error message list.\n錯誤訊息列表。")]
public string[] errorMsg
Field Value
| Type | Description |
|---|---|
| System.String[] |
extendedASCIIEncoding
Encode method.
解碼方法。
Declaration
[Header("[Gerenal]")]
[Tooltip("Encode method.\n解碼方法。")]
public static Encoding extendedASCIIEncoding
Field Value
| Type | Description |
|---|---|
| System.Text.Encoding |
hostMsg
Message when start networking.
開始連線的訊息。
Declaration
[Tooltip("Message when start networking.\n開始連線的訊息。")]
public string hostMsg
Field Value
| Type | Description |
|---|---|
| System.String |
ip
Server IP address.
伺服器 IP 位址。
Declaration
[Tooltip("Server IP address.\n伺服器 IP 位址。")]
public string ip
Field Value
| Type | Description |
|---|---|
| System.String |
isHosting
Return true if the user type is not client.
當使用者類型不是客戶端時傳回 true。
Declaration
[Tooltip("Return true if the user type is not client.\n當使用者類型不是客戶端時傳回 true。")]
public bool isHosting
Field Value
| Type | Description |
|---|---|
| System.Boolean |
joinMsg
Message when connect to server.
連至伺服器的訊息。
Declaration
[Header("[Client]")]
[Tooltip("Message when connect to server.\n連至伺服器的訊息。")]
public string joinMsg
Field Value
| Type | Description |
|---|---|
| System.String |
log
Reported data.
已回報的數據。
Declaration
[Tooltip("Reported data.\n已回報的數據。")]
public List<string> log
Field Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.String> |
maxConnections
Max user count in the connetion.
連線的最大使用者數目。
Declaration
[Header("[Server]")]
[Tooltip("Max user count in the connetion.\n連線的最大使用者數目。")]
public int maxConnections
Field Value
| Type | Description |
|---|---|
| System.Int32 |
messageWithName
Send message with user name if true.
當 true 時傳送的訊息會顯示使用者名稱。
Declaration
[Tooltip("Send message with user name.\n傳送的訊息會顯示使用者名稱。")]
public bool messageWithName
Field Value
| Type | Description |
|---|---|
| System.Boolean |
networkName
Uesr name in connection.
連線用的使用者名稱。
Declaration
[Tooltip("Uesr name in connection.\n連線用的使用者名稱。")]
public string networkName
Field Value
| Type | Description |
|---|---|
| System.String |
numberOfConnection
Current user count.
目前的使用者數目。
Declaration
[Header("[Status]")]
[Tooltip("Current user count.\n目前的使用者數目。")]
public int numberOfConnection
Field Value
| Type | Description |
|---|---|
| System.Int32 |
ownPort
Client port of UDP.
UDP 需要的客戶連接埠。
Declaration
[Tooltip("Client port of UDP.\nUDP 需要的客戶連接埠。")]
public int ownPort
Field Value
| Type | Description |
|---|---|
| System.Int32 |
port
Server port.
伺服器連接埠。
Declaration
[Tooltip("Server port.\n伺服器連接埠。")]
public int port
Field Value
| Type | Description |
|---|---|
| System.Int32 |
protocol
Communication protocol.
通訊協定。
Declaration
[Tooltip("Communication protocol.\n通訊協定。")]
public Protocol protocol
Field Value
| Type | Description |
|---|---|
| Protocol |
quitMsg
Message when disconnect to server.
離開伺服器的訊息。
Declaration
[Tooltip("Message when disconnect to server.\n離開伺服器的訊息。")]
public string quitMsg
Field Value
| Type | Description |
|---|---|
| System.String |
reconnect
Auto reconnect one time if failed to connect or lost connection.
當連線失敗或失去連線時自動重新連線一次。
Declaration
[Tooltip("Auto reconnect one time if failed to connect or lost connection.\n當連線失敗或失去連線時自動重新連線一次。")]
public bool reconnect
Field Value
| Type | Description |
|---|---|
| System.Boolean |
state
Connection state of networking.
網絡連線狀態。
Declaration
[Tooltip("Connection state of networking.\n網絡連線狀態。")]
public ConnectionState state
Field Value
| Type | Description |
|---|---|
| ConnectionState |
stopMsg
Message when stop networking.
關閉連線的訊息。
Declaration
[Tooltip("Message when stop networking.\n關閉連線的訊息。")]
public string stopMsg
Field Value
| Type | Description |
|---|---|
| System.String |
timeout
Times for fail or lost connection.
容許失敗及失去連線的次數。
Declaration
[Tooltip("Times for fail or lost connection.\n容許失敗及失去連線的次數。")]
public int timeout
Field Value
| Type | Description |
|---|---|
| System.Int32 |
type
User type on connection.
連線使用者類型。
Declaration
[Tooltip("User type on connection.\n連線使用者類型。")]
public UserType type
Field Value
| Type | Description |
|---|---|
| UserType |
Methods
ChangeName(String, Boolean)
Change the own network user name.
更改自身網絡使用者名稱。
ChangeName("UserB")
Declaration
public void ChangeName(string name, bool message = true)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | name | New name |
| System.Boolean | message | Show message if true |
Connect(String, Int32)
Connect to server.
連至伺服器。
Connect("192.168.0.100", 7777)
Declaration
public void Connect(string ip = "localhost", int port = 7777)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | ip | Server IP address |
| System.Int32 | port | Server port |
Disconnect()
Disconnect to server.
離開伺服器。
Declaration
public void Disconnect()
Host()
Start networking as a host.
作為伺服器及客戶開始連線。
Declaration
public void Host()
Send(String, Int32[])
Send message.
傳送訊息。
Send("Hello World!")
Declaration
public void Send(string message, params int[] receiver)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | message | Message |
| System.Int32[] | receiver | Specific users ID |
StartServer()
Start networking as a server.
作為伺服器開始連線。
Declaration
public void StartServer()
StopServer()
Stop server.
關閉連線。
Declaration
public void StopServer()