How to improve the robustness of the socket Client in C #

Source: Internet
Author: User


I am a newbie to Socket. I recently developed a Socket Client program. When I connect to the Server, if the server exists and the connection is allowed, the program runs normally. However, if the Server does not exist, or, if the connection is denied, the program gets stuck and no error is prompted. At first, I thought there was no Catch exception, but I checked the program and caught all the exceptions. The program was still stuck.
Please correct me! Thank you. The following is my code for this module!
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Net;
Using System. Net. Sockets;
Using System. Threading;
Using System. Text;
Namespace Test Program
{
/// <Summary>
/// Summary of ClassClient.
/// </Summary>
Public class ClassClient
{
// Method
Public ClassClient ()
{
//
// TODO: add the constructor logic here
//
}
// Function
# Region socket communication machine connection Function
/// <Summary>
/// Socket communication machine connection Function
/// </Summary>
/// <Param name = "remoteEP"> Remote Terminal </param>
/// <Param name = "client"> Create a client </param>
Public byte SocketConnect (EndPoint RemoteEP, Socket Client)
{
// Call the system connection Function
Client. BeginConnect (RemoteEP, new AsyncCallback (ConnectCallback), Client );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.