Porting
Background
The Windows Phone Tic-Tac-Toe Over Sockets Sample shows how TCP Sockets can be used on Windows Phone to communicate with a TCP Server. The main idea of this porting to Qt on Symbian is to demonstrate socket communication between Windows Phone and Qt on Symbian.
To make this porting compatible with the Windows Phone sample, we kept the communication protocol consistent with the Windows Phone sample. We implemented a communication server within this porting to which the Windows Phone connects. Furthermore, we also wanted two devices using our port to be able to play among themselves, so we also implemented a communication client within our port.
Socket communication between Qt and Windows Phone
The Windows Phone example acts as a client, which connects to a TCP server. Therefore, in our Qt port, we have a QTcpServer which listens on a certain address and port for incoming connections. The listen() method initiates listening for incoming connections, and whenever a client connects to the server, newConnection() signal is emitted. nextPendingConnection() accepts the pending incoming connection and returns a pointer to QTcpSocket in QAbstractSocket::ConnectedState, which can then be used to send and receive data from the connected host.
Whenever there is new data available on the socket (QTcpSocket), readyRead()signal is emitted. Then messages can be read calling the socket's read functions i.e. readAll() which returns a QByteArray. To send data to the host, QByteArray is passed to the write() method of the socket.
On the Windows Phone side, Socket class in System.Net.Sockets namespace provides support for TCP Socket communication. The connection to host and server is initiated using the ConnectAsync(SocketAsyncEventArgs) method. Remote host address, port, and event handler for Completed event is provided through SocketAsyncEventArgs. The Completed event is generated whenever any asynchronous operation related to the socket is completed, thus calling the event handler.
Data can be sent and received from the socket, using the SocketAsync(SocketAsyncEventArgs) and ReceiveAsync(SocketAsyncEventArgs) methods. Sending and receiving data on the socket can be disabled using Shutdown() method. The connection can be closed and resources released using the Close() method.
Protocol
The client sends the whole game board and the state of every block to the server. The server sends back one value: the name of the block which is its game piece to play. That is all that is needed from the server to make a move on the client board.

