Untitled
unknown
plain_text
a year ago
1.5 kB
13
Indexable
using System;
using System.Net.Sockets;
using System.Text;
class Program
{
static void Main()
{
string serverIp = "azdedldn.duckdns.org";
int port = 9874;
TcpClient tcpClient = new TcpClient();
try
{
tcpClient.Connect(serverIp, port);
NetworkStream networkStream = tcpClient.GetStream();
Console.WriteLine("Bağlantı başarılı. Sohbete başlamak için mesajınızı yazın:");
while (true)
{
Console.Write("Mesajınızı yazın (exit ile çıkabilirsiniz): ");
string messageToSend = Console.ReadLine();
if (messageToSend.ToLower() == "exit")
break;
byte[] messageBytes = Encoding.ASCII.GetBytes(messageToSend);
networkStream.Write(messageBytes, 0, messageBytes.Length);
byte[] responseBytes = new byte[1024];
int bytesRead = networkStream.Read(responseBytes, 0, responseBytes.Length);
string responseText = Encoding.ASCII.GetString(responseBytes, 0, bytesRead);
Console.WriteLine(responseText);
}
}
catch (Exception e)
{
Console.WriteLine("Hata: " + e.Message);
}
finally
{
tcpClient.Close();
}
}
}
Editor is loading...
Leave a Comment