OnConnectedToServer not working

I’ve created a server client model and successfully connect to a server of my program

However the OnConnectedToServer doesn’t triggered even if the console already got the message from Network (I change the debug mode to “full”)

here’s the code, the OnConnectedToServer is written near the end.

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using System.Collections.Generic;



public class serverlist : MonoBehaviour {
	private string registeredgamehost = "XXXXXXXXXX1233543543";
	private float refreshRequestLength = 3f;
	private HostData[] hostData;
	public GameObject samplebutton;
	public Transform contentpanel;
	public List<HostData> selectData = new List<HostData>();
	public List<GameObject> buttons = new List<GameObject>();

	[SerializeField] private InputField inputfield = null; // assign in the editor
	// Use this for initialization
	void Start () {
		inputfield = gameObject.GetComponent<InputField> ();
		Application.runInBackground = true;
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public IEnumerator refreshserverlist(){
		Debug.Log ("Refreshing...");
		MasterServer.RequestHostList (registeredgamehost);
		float start_time = Time.time;
		float end_time = start_time + refreshRequestLength;
		while (Time.time<end_time) {
			hostData = MasterServer.PollHostList();
			yield return new WaitForEndOfFrame();
		}
		Debug.Log ("number of hosts: "+hostData.Length);
		listdesire ();
	}

	public void refresh(){
		StartCoroutine ("refreshserverlist");
	}

	public void listdesire(){
		Debug.Log("start extracting");
		for (int i=0; i<buttons.Count; i++) {
			Destroy(buttons*);*
  •  }*
    
  •  buttons.Clear();*
    
  •  selectData.Clear ();*
    
  •  string key = inputfield.text;*
    
  •  Debug.Log ("user input: " + key);*
    
  •  for (int i=0; i<hostData.Length; i++) {*
    

if(hostData_.gameName.Contains(key)&&hostData*.connectedPlayers<2){
selectData.Add(hostData);
}
}
Debug.Log (“the list contains”+selectData.Count+“elements”);*_

* foreach (HostData temp in selectData) {*
* GameObject newbutton = Instantiate(samplebutton) as GameObject;*
* SampleButton button = newbutton.GetComponent();
button.nameLabel.text = temp.gameName;
button.hostdata = temp;
button.button.onClick.AddListener(() => connection_setup(temp));*
* newbutton.transform.SetParent(contentpanel);*

* buttons.Add(newbutton);*

* }*
* }*

* public void connection_setup(HostData data){
_ Network.Connect (data);
}*_

* void OnConnectedToServer() {*
* Debug.Log(“Connected to server”);*
* }*

* void onFailedToConnect(){*
* Debug.Log (“Fail to connect”);*
* }*
}

anybody have an idea where might be wrong?

from what I have read onConnectToServer() is part of the legacy pack. I would use
public override void OnStartClient(){
Debug.Log (“on start client”);
base.OnStartClient ();
}
https://docs.unity3d.com/ScriptReference/Networking.NetworkManager.html