TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Member1
NA
169
50.9k
How to close TcpClient object ?
Jul 17 2015 6:25 AM
I want to close and dispose TcpClient object and TcpListener object in proper way in form clossing event how to do that?. I tried some code for this but exception still displays. help me .
Thanks
here is my code<
public void startServer()
{
int port = Convert.ToInt32(txtport.Text);
string ipaddre = getip();
IPAddress iP = IPAddress.Parse(ipaddre);
var serverSocket = new TcpListener(iP, port);
var clientSocket = default(TcpClient);
int counter = 0;
Form1 f1 = new Form1();
serverSocket.Start();
AppendTxtdata("Server Started , Waiting for Client Connection");
IsRunning = true;
try
{
while (IsRunning)
{
counter += 1;
clientSocket = serverSocket.AcceptTcpClient();
AppendTxtdata(" >> " + "Client No:" + Convert.ToString(counter) + " Connected-- IP --" + clientSocket.Client.RemoteEndPoint.ToString() + "");
AppendTxtdata(Environment.NewLine);
handleClient client = new connectSuccess.handleClient();
client.startClient(clientSocket, Convert.ToString(counter));
// break;
}
AppendTxtdata("Data sent to Client No :" + Convert.ToString(counter));
//clientSocket.Close();
//serverSocket.Stop();
}
catch { }
finally
{
clientSocket.Close();
serverSocket.Stop();
}
}
I don't have access of these objects out of this method.
Reply
Answers (
1
)
Api Using error
code to freeze excel rows using c#...?? Help ??