-
Notifications
You must be signed in to change notification settings - Fork 7
/
Client.cs
46 lines (41 loc) · 1.23 KB
/
Client.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Linq;
using System.Net;
using System.IO;
using System.IO.Pipes;
using System.Net.Sockets;
using System.Threading;
using System.Runtime.InteropServices;
using System.Text;
namespace Sharpcat
{
public class Client
{
public static bool Connect(String ipaddress, int port, out Socket client)
{
IPAddress ip = IPAddress.Parse(ipaddress);
//Console.WriteLine("Connecting to IP address {0} and port {1}", ip.ToString(), port);
IPEndPoint remoteEP = new IPEndPoint(ip, port);
client = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
try
{
client.Connect(remoteEP);
}
catch (SocketException se)
{
Console.WriteLine("SocketException : {0}", se.ToString());
return false;
}
catch (Exception e)
{
Console.WriteLine("Unexpected exception : {0}", e.ToString());
return false;
}
return true;
}
public static void Close(Socket client)
{
client.Close();
}
}
}