0% found this document useful (0 votes)
4 views1 page

TCP Client

This document contains a C# program that implements a simple TCP client. It prompts the user for a server IP address and allows the user to send text messages to the server, receiving responses in return. The client connects to the server on port 1308 and continues to loop for user input until terminated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

TCP Client

This document contains a C# program that implements a simple TCP client. It prompts the user for a server IP address and allows the user to send text messages to the server, receiving responses in return. The client connects to the server on port 1308 and continues to loop for user input until terminated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace Client
{
internal class Program
{
private static void Main()
{
Console.Write("Server Ip: ");
var ip = IPAddress.Parse(Console.ReadLine());
while (true)
{
Console.Write("# Text >>> ");
var text = Console.ReadLine();
var client = new TcpClient();
client.Connect(ip, 1308);
var stream = client.GetStream();
var writer = new StreamWriter(stream) { AutoFlush = true };
var reader = new StreamReader(stream);
writer.WriteLine(text);
var response = reader.ReadLine();
client.Close();
Console.WriteLine(response);
}
}
}
}

You might also like