Click here to Skip to main content
11,721,053 members (77,422 online)
Click here to Skip to main content

X-O Game Through LAN

, 19 Dec 2007 CPOL 41.5K 2.2K 26
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Galaxy
Software Developer Biomedical Engineering Software
Egypt Egypt
I Graduated from Biomedical and Systems Engineering july 2008 department faculty of engineering cairo university. and am interested in the field of Biomedical Engineering Software. as i think its very powerful & interseting field.

You may also be interested in...

Comments and Discussions

 
QuestionCode Pin
lejanei15-Mar-14 5:19
memberlejanei15-Mar-14 5:19 
QuestionHi Pin
jayjaycon14-Jan-12 0:08
memberjayjaycon14-Jan-12 0:08 
GeneralMy vote of 1 Pin
Ravi Sant5-Jan-12 9:34
memberRavi Sant5-Jan-12 9:34 
Please post source code and explanation
GeneralMy vote of 1 Pin
freedom_fence9-Mar-10 20:08
memberfreedom_fence9-Mar-10 20:08 
GeneralNo source Pin
bloo200729-Jun-09 6:24
memberbloo200729-Jun-09 6:24 
GeneralMy vote of 1 Pin
Caydence13-May-09 9:34
memberCaydence13-May-09 9:34 
QuestionHow to Play Pin
Preet8112-Nov-08 22:06
memberPreet8112-Nov-08 22:06 
Generalhello! Pin
Betty57-Jul-08 0:40
memberBetty57-Jul-08 0:40 
QuestionVery Nice application, want to look at source...BUT where is the source? Pin
AnandChavali19-Dec-07 19:10
memberAnandChavali19-Dec-07 19:10 
Generalu is spelled Y.O.U. ur is Y.O.U.R. Pin
J4amieC19-Dec-07 4:11
mvpJ4amieC19-Dec-07 4:11 
GeneralRe: u is spelled Y.O.U. ur is Y.O.U.R. Pin
Galaxy19-Dec-07 5:26
memberGalaxy19-Dec-07 5:26 
GeneralRe: u is spelled Y.O.U. ur is Y.O.U.R. Pin
J4amieC19-Dec-07 22:39
mvpJ4amieC19-Dec-07 22:39 
Generalnice but Pin
Mohammad Elwakeel18-Dec-07 19:42
memberMohammad Elwakeel18-Dec-07 19:42 
GeneralRe: nice but Pin
Galaxy18-Dec-07 21:38
memberGalaxy18-Dec-07 21:38 
QuestionWhere is the source? Pin
BGaddis18-Dec-07 15:37
memberBGaddis18-Dec-07 15:37 
QuestionCan we make it 3D :) Pin
ahmed_saad18-Dec-07 14:59
memberahmed_saad18-Dec-07 14:59 
Generalshekka Pin
shekka18-Dec-07 12:59
membershekka18-Dec-07 12:59 
Generalhoba Pin
hoba_scorpion18-Dec-07 12:24
memberhoba_scorpion18-Dec-07 12:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 19 Dec 2007
Article Copyright 2007 by Galaxy
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid