tic tac toe online

i want to bring my game online using UDP but when i open 2 of this application the second one doesnt receive anything i dont know why please tell me why its my project for my school thnx alot :D oh and its very long so i had to cut some of my program but the send and receive is both here


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        UdpClient udps;
        int a = 0;
        
        public Form1()
        {
            InitializeComponent();
            
            
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            udps = new UdpClient();
        }
        private void Mainn(string[] args)
        {
            UdpClient udps = new UdpClient(10002);
            IPEndPoint ipep = null;
            while (true)
            {

                byte[] bindata = udps.Receive(ref ipep);
                string data = Encoding.ASCII.GetString(bindata);
                
                byte[] binhavij = udps.Receive(ref ipep);
                string havij = Encoding.ASCII.GetString(binhavij);
                

                if (data == "O" && havij == ",3")
                    button3.Text = "O";



            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (button5.Text != "Player")
            {
                if (button3.Text != "X" && button3.Text != "O")
                {
                    if (a % 2 == 0)
                    {
                        button3.Text = "X";
                        a++; 
                        byte[] havij = Encoding.ASCII.GetBytes(",3");
                        byte[] data = Encoding.ASCII.GetBytes(button3.Text);
                        udps.Send(data, data.Length, "127.0.0.1", 10001);
                        udps.Send(havij, havij.Length, "127.0.0.1", 10001);
                    }
                    else
                    {
                        button3.Text = "O";
                        a++;
                        byte[] havij = Encoding.ASCII.GetBytes(",3");
                        byte[] data = Encoding.ASCII.GetBytes(button3.Text);
                        udps.Send(data, data.Length, "127.0.0.1", 10001);
                        udps.Send(havij, havij.Length, "127.0.0.1", 10001);
                    }
                }
                if (button1.Text == "X" && button2.Text == "X" && button3.Text == "X")
                {
                    button1.Text = "";
                    button2.Text = "";
                    button3.Text = "";
                    button4.Text = "X ";
                    button5.Text = "Player";
                    button6.Text = "Wins!";
                    button7.Text = "";
                    button8.Text = "";
                    button9.Text = "";


                }
                if (button1.Text == "O" && button2.Text == "O" && button3.Text == "O")
                {
                    button1.Text = "";
                    button2.Text = "";
                    button3.Text = "";
                    button4.Text = "O";
                    button5.Text = "Player";
                    button6.Text = "Wins!";
                    button7.Text = "";
                    button8.Text = "";
                    button9.Text = "";


                }
                if (button3.Text == "O" && button6.Text == "O" && button9.Text == "O")
                {
                    button1.Text = "";
                    button2.Text = "";
                    button3.Text = "";
                    button4.Text = "O ";
                    button5.Text = "Player";
                    button6.Text = "Wins!";
                    button7.Text = "";
                    button8.Text = "";
                    button9.Text = "";
                }
                if (button3.Text == "X" && button6.Text == "X" && button9.Text == "X")
                {
                    button1.Text = "";
                    button2.Text = "";
                    button3.Text = "";
                    button4.Text = "X ";
                    button5.Text = "Player";
                    button6.Text = "Wins!";
                    button7.Text = "";
                    button8.Text = "";
                    button9.Text = "";
                }
                if (button7.Text == "X" && button5.Text == "X" && button3.Text == "X")
                {
                    button1.Text = "";
                    button2.Text = "";
                    button3.Text = "";
                    button4.Text = "X ";
                    button5.Text = "Player";
                    button6.Text = "Wins!";
                    button7.Text = "";
                    button8.Text = "";
                    button9.Text = "";


                }
                if (button7.Text == "O" && button5.Text == "O" && button3.Text == "O")
                {
                    button1.Text = "";
                    button2.Text = "";
                    button3.Text = "";
                    button4.Text = "O ";
                    button5.Text = "Player";
                    button6.Text = "Wins!";
                    button7.Text = "";
                    button8.Text = "";
                    button9.Text = "";
                }
            }
        }}
    }
}
Topic archived. No new replies allowed.