Device-to-device (D2D) communications enable direct communications among mobile entities, which brings new revolutions to existing cellular networks. Many use cases which can benefit from D2D are introduced such as vehicles-to-vehicles communication, vehicles-to-infrastructure communication, machine-to-machine communication, and so on. With the help of these information communication techniques, we propose a real-time traffic signal control approach to relieve traffic problems in this paper. Currently, a series of traffic problems, such as traffic congestion, traffic accidents, and vehicle exhaust emission, are increasingly inconveniencing city residents, especially in rush hours. One of the most dominating approaches to relieve the traffic congest is to determine the phase timing of traffic signals. However, a major shortcoming of the existing phase timing related control strategies is of highly computational complexity, which causes, to some extent, a response delay. The approach based on D2D communication, in this paper, on one hand can collect data of various types via sensors and actuators and on the other hand can reduce the response time as much as possible. Specifically, considering an intersection with four legs, we encoded the corresponding set of signal lights of each leg using a genetic algorithm. To evaluate the efficiency of phase timing plan in this paper, we have conducted extensive simulations, and the results show that our approach can respond to the considered traffic flow within one second. Compared with other traffic signal control systems, the performance is improved almost by 67% with regards to the queue length waiting at the intersections during traffic signal light cycle(s).