I made a program server and client, The problem is that I don't know how to send the data from Server to Client for example from listBox at a Server to show those data in a client Listbox.
I made some code but still no result.
private string ip = "127.0.0.1";
private int port = 1234;
private TcpListener listener = null;
public void ListenClients()
{
listener = new TcpListener(IPAddress.Parse(ip), port);
listener.Start();
while (true)
{
Socket clientSocket = listener.AcceptSocket();
Thread thread = new Thread(ClientWorker);
thread.Name = clientSocket.RemoteEndPoint.ToString();
thread.Start(clientSocket);
}
}
private void ClientWorker(object objectSocket)
{
Socket socket = (Socket)objectSocket;
while (socket.Connected)
{
try
{
byte[] buffer = new byte[1024];
int readBytes = socket.Receive(buffer);
socket.Send = indeksLista.ConvertToByte[] ;
// socket.Send(LexoStudentetFajll());
string text = Encoding.UTF8.GetString(buffer, 0, readBytes);
Console.WriteLine("Client {0} Send: {1}", socket.RemoteEndPoint, text);
}
catch (Exception ex)
{
Console.WriteLine("ClientWorker Error: {0}", ex.Message);
}
}
}
I don't have a clue where I'm wrong or how to convert listbox items to a byte array.
Thank you in advance for your reply