/// <summary> /// Callback for when the user first connects to the server. /// Sends the player name off to the server. /// Sets the new callback to be for when we receive data. /// </summary> /// <param name="state"></param> private void connectCallbackFunc(Preserved_Socket_State state) { base.BeginInvoke(new MethodInvoker(() => updatePanel(false))); actionCallback handler = receivePlayerFunc; state.callback = handler; string name = playerName.Text + '\n'; Network.Send(state.workSocket, name); }
/// <summary> /// Handler for when the user clicks the connect button to connect to the server. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void connectButton_Click(object sender, EventArgs e) { errorLabel.Text = "Connecting..."; connectTimout = new System.Timers.Timer(3000); connectTimout.Elapsed += ConnectTimout_Elapsed; connectTimout.Start(); actionCallback handler = connectCallbackFunc; socket = Network.Connect_to_Server(handler, serverName.Text); }
/// <summary> /// Callback that happens when we receive the player data from the /// server. /// </summary> /// <param name="state"></param> private void receivePlayerFunc(Preserved_Socket_State state) { lock (worldInfo) { actionCallback handler = receiveDataFunc; state.callback = handler; state.sb.Append(encoding.GetString(state.buffer, 0, state.bytesRead)); string response = state.sb.ToString(); Cube playerCube = JsonConvert.DeserializeObject <Cube>(response); playerCubeUid = playerCube.uid; worldInfo.addCube(playerCube); hasPlayerCube = true; this.Invalidate(); Network.i_want_more_data(state); } }