Click here to Skip to main content
6,295,667 members and growing! (12,342 online)
Email Password   helpLost your password?
Languages » C# » Applications     Intermediate License: The Code Project Open License (CPOL)

X-O Game Through LAN

By Galaxy

Play X-O through TCP connection
C# (C# 1.0, C# 2.0, C# 3.0), Windows (Win2K, WinXP, Win2003, Vista, TabletPC, Embedded), Win32, Dev
Posted:18 Dec 2007
Updated:19 Dec 2007
Views:11,748
Bookmarked:13 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
9 votes for this article.
Popularity: 2.59 Rating: 2.71 out of 5
3 votes, 33.3%
1

2
1 vote, 11.1%
3
1 vote, 11.1%
4
4 votes, 44.4%
5
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)

About the Author

Galaxy


Member
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.
Occupation: Software Developer
Company: Biomedical Engineering Software
Location: Egypt Egypt

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Layout  Per page   
 Msgs 1 to 14 of 14 (Total in Forum: 14) (Refresh)FirstPrevNext
GeneralNo source Pinmemberbloo20077:24 29 Jun '09  
GeneralMy vote of 1 PinmemberCaydence10:34 13 May '09  
QuestionHow to Play PinmemberPreet8123:06 12 Nov '08  
Generalhello! PinmemberBetty51:40 7 Jul '08  
GeneralVery Nice application, want to look at source...BUT where is the source? PinmemberAnandChavali20:10 19 Dec '07  
Generalu is spelled Y.O.U. ur is Y.O.U.R. PinmvpJ4amieC5:11 19 Dec '07  
GeneralRe: u is spelled Y.O.U. ur is Y.O.U.R. PinmemberGalaxy6:26 19 Dec '07  
GeneralRe: u is spelled Y.O.U. ur is Y.O.U.R. PinmvpJ4amieC23:39 19 Dec '07  
Generalnice but PinmemberMohammad Elwakeel20:42 18 Dec '07  
GeneralRe: nice but PinmemberGalaxy22:38 18 Dec '07  
GeneralWhere is the source? PinmemberBGaddis16:37 18 Dec '07  
GeneralCan we make it 3D :) Pinmemberahmed_saad15:59 18 Dec '07  
Generalshekka Pinmembershekka13:59 18 Dec '07  
Generalhoba Pinmemberhoba_scorpion13:24 18 Dec '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 19 Dec 2007
Editor: Deeksha Shenoy
Copyright 2007 by Galaxy
Everything else Copyright © CodeProject, 1999-2009
Web17 | Advertise on the Code Project