-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPClient.cs
More file actions
54 lines (39 loc) · 1.2 KB
/
TCPClient.cs
File metadata and controls
54 lines (39 loc) · 1.2 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.IO;
/**
* @Author : JITHINRAJ.P
*
*
* */
namespace TCPClient
{
class TCPClient
{
private static TcpClient client;
static void Main(string[] args)
{
client = new TcpClient();
Console.WriteLine("Connecting to server");
client.Connect("127.0.0.1", 5150);
Console.WriteLine("Connected");
Console.WriteLine("enter The string to be transmitted");
String textToTransmit = Console.ReadLine();
Stream tcpStream = client.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(textToTransmit);
Console.WriteLine("Transmitting.....");
tcpStream.Write(ba, 0, ba.Length);
byte[] bb = new byte[100];
int k = tcpStream.Read(bb, 0, 100);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(bb[i]));
client.Close();
}
}
}