tak ja tady dam ten projekt protoze mi to porad dela to same tzn. ze jakmile dam klient = new TcpClient(ip.Text, Int32.Pars(port.Text)); na nejake tlacitko ktere spustim tak odeslu pouze prvni souradnice a dale uz ne... a ted nevim co s tim
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.IO;
namespace GAME
{
public partial class Form1 : Form
{
public static int a = 20;
public static int b = 20;
private MyButton button;
public Form1()
{
InitializeComponent();
groupBox1.Size = new Size(300, 300);
ukaz();
}
private MyButton[,] polebtn = new MyButton[a, b];
public void ukaz()
{
int c = 0;
int d = 0;
for (int i = 0; i < 300; i += 15)
{
for (int k = 0; k < 300; k += 15)
{
button = new MyButton();
button.BackColor = Color.White;
button.Location = new Point(k, i);
button.Size = new Size(15, 15);
button.X = c;
button.Y = d;
polebtn[c, d] = button;
button.Click += new EventHandler(button_Click);
groupBox1.Controls.Add(button);
c++;
}
c = 0;
d++;
}
}
private TcpClient klient = null;
private NetworkStream ns;
public void button_Click(object sender, EventArgs e)
{
MyButton send = (MyButton)sender;
polebtn[send.X, send.Y].BackColor = Color.Black;
string xx = send.X.ToString();
string yy = send.Y.ToString();
pripoj(xx, yy);
}
void pripoj(string xx, string yy)
{
ns = klient.GetStream();
Byte[] x;
x = System.Text.Encoding.ASCII.GetBytes(xx + "," + yy);
ns.Write(x, 0, x.Length);
// klient.Close();
//ns.Close();
}
private void button1_Click(object sender, EventArgs e)
{
klient = new TcpClient(ip.Text, Int32.Parse(port.Text));//zde nevim co s tim
}
}
}
a prijimac
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Sockets;
using GAME;
using System.Threading;
namespace PRIJIMAC
{
public partial class Form1 : Form
{
private ArrayList ooo = new ArrayList();
private Thread proc;
/// <summary>
public static int a = 20;
public static int b = 20;
private MyButton button;
private MyButton[,] polebtn = new MyButton[a, b];
public void ukaz()
{
int c = 0;
int d = 0;
for (int i = 0; i < 300; i += 15)
{
for (int k = 0; k < 300; k += 15)
{
button = new MyButton();
button.BackColor = Color.White;
button.Location = new Point(k, i);
button.Size = new Size(15, 15);
button.X = c;
button.Y = d;
polebtn[c, d] = button;
//button.Click += new EventHandler(button_Click);
groupBox1.Controls.Add(button);
c++;
}
c = 0;
d++;
}
}
/// </summary>
///
private TcpListener list;
private TcpClient klient;
public Form1()
{
InitializeComponent();
ukaz();
IPAddress ip = IPAddress.Parse("127.0.0.1");
list = new TcpListener(ip, 2112);
groupBox1.Size = new Size(300, 300);
proc = new Thread(new ThreadStart(slys));
proc.Start();
}
private int i = 0;
private string f, g;
private string xxx;
public void slys()
{
list.Start();
while (true)
{
string[] words;
klient = list.AcceptTcpClient();
NetworkStream str = klient.GetStream();
Byte[] data = new Byte[10];
str.Read(data, 0, data.Length);
xxx = System.Text.Encoding.ASCII.GetString(data);
words = xxx.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
// polebtn[System.Convert.ToInt32(g), System.Convert.ToInt32(f)].BackColor = Color.Black;
polebtn[Int32.Parse(words[0]), Int32.Parse(words[1])].BackColor = Color.Black;
// proc.Start();
//list.Stop();
//klient.Close();
//str.Close();
}
}
}
}