Untitled
unknown
plain_text
a year ago
1.4 kB
10
Indexable
using System;
using System.Net.Sockets;
using System.Text;
class Program
{
static void Main()
{
string serverIp = "217.131.126.248";
int port = 9874;
try
{
TcpClient client = new TcpClient(serverIp, port);
NetworkStream stream = client.GetStream();
Console.WriteLine("Bağlantı başarılı. Sohbet mesajı:");
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);
stream.Write(messageBytes, 0, messageBytes.Length);
byte[] buffer = new byte[256];
int bytesRead = stream.Read(buffer, 0, buffer.Length);
string response = Encoding.ASCII.GetString(buffer, 0, bytesRead);
Console.WriteLine(response);
}
client.Close();
}
catch (Exception e)
{
Console.WriteLine("Bağlantı hatası: " + e.Message);
}
}
}
Editor is loading...
Leave a Comment