public void SendSingleClient()
{
// Connect to a remote device.
try
{
// Establish the remote endpoint for the socket.
// The name of the
// remote device is "host.contoso.com".
IPAddress ipAddress = (Dns.GetHostAddresses(targetip))[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress,Int32.Parse(targetport));
//Socket client = new Socket(AddressFamily.InterNetwork,
// SocketType.Stream, ProtocolType.Tcp);
{
// Create a TCP/IP socket.
Socket client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
// Connect to the remote endpoint.
client.BeginConnect(remoteEP,
new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
// Send test data to the remote device.
string m = SingleMsg + "<EOF>";
Send(client, m);
sendDone.WaitOne();
// Receive the response from the remote device.
//Receive(client);
//receiveDone.WaitOne();
// Write the response to the console.
//Console.WriteLine("Response received : {0}", response);
// Release the socket.
client.Shutdown(SocketShutdown.Both);
client.Close();
}
}
catch (Exception e)
{
//System.Windows.Forms.MessageBox.Show(e.Message, "Failed to send to single client.");
// Console.WriteLine(e.Message);
Console.WriteLine("Please check the IP " + e.Message);
int ErrorCode = 10;
string Error = "Please Check the IP";
if (ErrorExcep != null)
ErrorExcep(ErrorCode, Error);
}
}