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 );