-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.txt
More file actions
35 lines (31 loc) · 1.09 KB
/
client.txt
File metadata and controls
35 lines (31 loc) · 1.09 KB
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
class Program
{
static void Main(string[] args)
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7000);
s.Connect(ep);
string key = string.Empty;
byte[] buffer = new byte[1024];
Console.WriteLine("connected...enter Q to exit");
while((key = Console.ReadLine()) != "Q")
{
try
{
byte[] msg = Encoding.UTF8.GetBytes(key);
s.Send(msg, SocketFlags.None);
int nbytes = s.Receive(buffer);
Console.WriteLine(Encoding.UTF8.GetString(buffer, 0, nbytes));
}
catch(SocketException e)
{
Console.WriteLine(e.Message + e.ErrorCode);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
s.Close();
}
}