If you gave us what you were sending I could help you out a tad more, I'm also not sure what you mean by "send gridview data from SERVER to CLIENT", server's are used to recv and client's send. I guess i can give you an example of a TcpClient and TcpServer's from another project I wrote a while ago.
TCP Server
using System;
using System.Linq;
using System.Text;
using System.Threading;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
namespace MyNamespace
{
public class Server
{
public delegate void MessageReceived(string sender, string message, DateTime time);
public event MessageReceived OnRecv;
private Thread listen;
private Thread answer;
private TcpListener listener;
private List<tcpclient> clients = new List<tcpclient>();
public TcpClient[] Connections
{
get
{
return clients.ToArray();
}
}
public int Port { get; set; }
private void Answer()
{
int num = 0;
while (true)
{
if (clients.Count == 0)
continue;
if (clients.Count <= num)
num = 0;
NetworkStream s = clients[num].GetStream();
if (s.DataAvailable)
{
byte[] buffer = new byte[clients[num].ReceiveBufferSize];
s.Read(buffer, 0, buffer.Length);
string recv = Encoding.ASCII.GetString(buffer).Replace("\0", "");
if (OnRecv != null)
OnRecv(clients[num].Client.RemoteEndPoint.ToString(), recv, DateTime.Now);
}
num++;
}
}
private void Listen()
{
try
{
listener.Start(10);
}
catch { throw new Exception("PORT " + Port + " is already running!"); }
while (true)
clients.Add(listener.AcceptTcpClient());
}
public void Start()
{
if (listen != null && answer != null)
{
if (!listen.IsAlive && !answer.IsAlive)
{
listen.Start();
answer.Start();
}
}
}
public void Stop()
{
if (listen != null && answer != null)
{
if (listen.IsAlive && answer.IsAlive)
{
listen.Abort();
answer.Abort();
}
}
}
public Server(int port)
{
try
{
listener = new TcpListener(new IPEndPoint(IPAddress.Any, port));
listener.AllowNatTraversal(true);
}
catch
{
throw new Exception("Unexpected server crash.");
}
finally
{
listen = new Thread(() => Listen());
answer = new Thread(() => Answer());
Port = port;
}
}
}
}
TCP Client
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace MyNamespace
{
public class Client
{
private TcpClient client;
public void Send(IPEndPoint ep, string message)
{
if (client == null)
{
client = new TcpClient();
client.Connect(ep);
NetworkStream s = client.GetStream();
byte[] buffer = Encoding.ASCII.GetBytes(message);
s.Write(buffer, 0, buffer.Length);
}
else
{
if (!client.Connected)
client.Connect(ep);
NetworkStream s = client.GetStream();
byte[] buffer = Encoding.ASCII.GetBytes(message);
s.Write(buffer, 0, buffer.Length);
}
}
public void Send(IPEndPoint[] endpoints, string message)
{
foreach (IPEndPoint ep in endpoints)
Send(ep, message);
}
public void Send(IPAddress[] addresses, int port, string message)
{
foreach (IPAddress ip in addresses)
Send(new IPEndPoint(ip, port), message);
}
public Client()
{
}
}
}
How to:
To use the TCPServer make sure you use the OnRecv event then use Start();
To use the TCPClient just suse the send functions, pretty easy.