private void Form1_FormClosing(object sender, FormClosingEventArgs e) { client.Shutdown(SocketShutdown.Both);//error :Object reference not sent to an instance of an object client.Close(); }
private void Form1_Load(object sender, EventArgs e) { IPAddress host = IPAddress.Parse("192.168.0.100"); hostep = new IPEndPoint(host, 8001); sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { sock.Connect(hostep); timer1.Enabled = true; } catch (Exception a) { label1.Text = a.Message; } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (client!=null) { client.Shutdown(SocketShutdown.Both);// no NullRefExc client.Close(); } }
sock
Load
client
FormClosing
Socket
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)