In this paper we study the control of switching servers, which can for example be found in manufacturing industry. In general, these systems are discrete event systems. A server processes multiple job types. Switching between the job types takes time and during that time, no jobs can be processed, so capacity is lost. How should a server switch between the job types in an efficient way? In this paper we derive the optimal process cycle with respect to work in process levels for a server with two job types and finite buffer capacities. The analysis is performed using a hybrid fluid model approximation. After the optimal process cycle has been defined, a state feedback controller is proposed that steers the trajectory of the system to this optimal cycle. Workstations are often placed in series to form a flowline of servers. Our goal is to control flowlines of switching servers in a way that the work in process level is minimized. In a flowline, only the most downstream workstation influences the work in process level of the system, since upstream workstations simply move jobs from one server to the other. If it is possible to have the most downstream workstation process in its optimal cycle and the other workstations can make this happen, then optimal work in process levels are achieved. This paper investigates under which conditions the upstream workstations can make the most downstream workstation work optimally. Conditions on the upstream workstations are derived and the class of flowlines is characterized for which the optimal process cycle of an isolated downstream workstation can become the optimal process cycle for the flowline. For a flowline consisting of two workstations, a state feedback controller is proposed and convergence to the optimal process cycle is proved mathematically. An extensive case study demonstrates how the controller performs, for both the hybrid fluid model and in a discrete event implementation with stochastic inter-arrival and process times.