Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

X-O Game Through LAN

0.00/5 (No votes)
19 Dec 2007 1  
Play X-O through TCP connection
Screenshot - Code1.jpg

Screenshot - Code2.jpg

Screenshot - Presentation1[][[.jpg

Introduction

This code was used to implement the Tic-Tac-Toe game and play it through the LAN with a friend. Of course, we use the TCP protocol to send instructions.

Background

The TCP protocol is used to send reliable data through the network. In order to understand this code well, you must first have a general overview about the TCP transmission protocol.

Using the Code

In this project, we have two separate programs, one for the server that manages the entrance of the players and to hold messages from one player to another. The other program is the part for the clients (i.e. players) that listen to any messages coming from the server. It also performs some Event Handlers and the most important part is THREADING. For the clients, they are TCP clients for the server that listen at port 5000 for client requests.

Parts from the code look like this:

//TCP client
TcpClient client = new TcpClient("localhost", 5000);
                output = client.GetStream();
                writer = new BinaryWriter(output);
                sendr = (PictureBox)sender;    

//TCP listener
TcpListener tcplistner = new TcpListener(5000);
           tcplistner.Start();
            while (true)
            {
                
                welsock = tcplistner.AcceptSocket();
                networkstream = new NetworkStream(welsock);
                reader = new BinaryReader(networkstream);
                writer = new BinaryWriter(networkstream);

For any further details, please don't hesitate to contact me.

Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here