how to correct this error c# code?
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.Threading;
using System.Net.Sockets;
using System.IO;
using System.Net;
namespace P1
{
public partial class P1 : Form
{
private static Socket client;
private static byte[] datae = new byte[1024];
private System.Windows.Forms.OpenFileDialog openFile;
public P1()
{
InitializeComponent();
}
private void AddToListBox(object oo)
{
Invoke(new MethodInvoker(
delegate { results.Items.Add(oo); }
));
}
void AcceptConn(IAsyncResult iar)
{
Socket oldserver = (Socket)iar.AsyncState;
client = oldserver.EndAccept(iar);
AddToListBox("Connection from: " + client.RemoteEndPoint.ToString());
Thread receiver = new Thread(new ThreadStart(ReceiveData));
receiver.Start();
}
void Connected(IAsyncResult iar)
{
try
{
client.EndConnect(iar);
AddToListBox("Connected to: " + client.RemoteEndPoint.ToString());
Thread receiver = new Thread(new ThreadStart(ReceiveData));
receiver.Start();
}
catch (SocketException)
{
AddToListBox("Error connecting");
}
}
void SendData(IAsyncResult iar)
{
Socket remote = (Socket)iar.AsyncState;
int sent = remote.EndSend(iar);
}
void ReceiveData()
{
int recv;
string data;
while (true)
{
byte[] data = new byte[1024];
recv = client.Receive(data);
string data =Encoding.ASCII.GetString(data , 0, recv);
if (string data == "bye")
break;
{
}
else ( (string data == "file")){
}
AddToListBox(stringData);
{
string data = "bye";
byte[] message = Encoding.ASCII.GetBytes(stringData);
client.Send(message);
client.Close();
AddToListBox("Connection stopped");
return;
{
private void connect_Click_1(object sender, EventArgs e)
{
AddToListBox("Connecting...");
client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Parse(""), 0);
}
private void listen_Click_1(object sender, EventArgs e)
{
AddToListBox("Listining to client");
Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, -1);
newsock.Bind(iep);
newsock.Listen(100);
}
private void sendit_Click_1(object sender, EventArgs e)
{
IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, 5656);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
sock.Bind(ipEnd);
sock.Listen(100);
Socket clientSock = sock.Accept();
byte[] messagea = Encoding.ASCII.GetBytes(txtMsg.Text);
txtMsg.Clear();
client.BeginSend(messagea, 0, messagea.Length, 0, new AsyncCallback(SendData), client);
string clientStr = "Client Data Received";
byte[] sendData = new byte[1024];
sendData= Encoding.ASCII.GetBytes(clientStr);
clientSock.Send(sendData);
}
public void ReciveFile()
{
try
{
}
catch (Exception ex)
{
Console.WriteLine("File Sending fail." + ex.Message);
}
}
public void SendFile(string fileName)
{
try
{
Console.WriteLine("That program can transfer small file. I've test up to 850kb file");
}
catch (Exception ex)
{
throw ex;
}
}
private void sendFile_Click(object sender, EventArgs e)
{
byte[] message = Encoding.ASCII.GetBytes("file");
if (openFile.ShowDialog(this) == DialogResult.OK)
txtFileName.Text = openFile.FileName;
client.BeginSend(message, 0, message.Length, 0, new AsyncCallback(SendData), client);
SendFile(System.IO.Path.GetFileName(txtFileName.Text.ToString()));
Console.ReadLine();
}
}