- Home /
Unitynetworking problem.
First off here is my error: error CS0117: 'UnityEngine.Networking.NetworkServer' does not contain a definition for 'SendToClient'
Here is my code:
using UnityEngine;
using System.Collections;
using CodeStage.AntiCheat.ObscuredTypes;
using UnityEngine.Networking;
public class log : MonoBehaviour {
string loginURL = "http://127.0.0.1/page/log.php"; // WEB SERVER
string problem = "";
private ObscuredString logMessage;
private ObscuredString userName;
private ObscuredString password;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Network.peerType == NetworkPeerType.Server) {
if (logMessage == "LoginRequest") {
StartCoroutine(handleLogin(userName, password));
}
}
}
IEnumerator handleLogin(ObscuredString userName, ObscuredString password) {
Debug.Log ("Login Request receved" + logMessage);
if (logMessage == "userName") {
logMessage = userName;
Debug.Log ("Username receved" + logMessage + userName);
}
if (logMessage == "password") {
logMessage = password;
Debug.Log ("Password receved" + logMessage + password);
}
if (userName && password != null) {
string login_URL = loginURL + "?mynick=" + userName + "&password=" + password;
WWW loginReader = new WWW(login_URL);
yield return loginReader;
if(loginReader.error != null) {
problem = "COULD NOT LOCATE PAGE";
} else {
if(loginReader.text == "right") {
NetworkServer.SendToClient<MSG>(ObscuredString);
[RPC]
networkView.RPC("right", RPCMode.Others);
networkView.RPC(problem = "LOGGED IN", RPCMode.Others);
} else {
problem = "INVALID USER/PASS";
}
}
}
}
}
I would like to send a string message to the client, and I would like to be able to send a string message to the server, but I am not sure how to do this.
You seem to mix Unity's old network system (RakNet) with the new system (UNet). The Network class and NetworkViews belong to the old networking system while everything inside the "UnityEngine.Networking" namespace belongs to the new system.
First of all you should choose one system. If you want to stick with the old system you should remove the "Networking" namespace and the "NetworkServer" line as it belongs to the new system. The RPC method takes a string that should represent an RPC method name. "LOGGED IN" can't possibly be a valid method name as it contains a space.