Мне код сервера исправить немного - C#
Формулировка задачи:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace Server
{
class Program
{
public static void Main(string[] args)
{
byte[] bytes = new byte[1024];
IPHostEntry ipHost = Dns.Resolve("//Хочу вводить IP адрес вручную");
IPAddress ipAddr = ipHost.AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);
Socket sListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
sListener.Bind(ipEndPoint);
sListener.Listen(10);
while (true)
{
Console.WriteLine("Waiting for connections...", ipEndPoint);
Socket handler = sListener.Accept();
string data = null;
int bytesRec = handler.Receive(bytes);
data += Encoding.ASCII .GetString(bytes, 0, bytesRec);
Console.WriteLine("Client Massage : {0}", data);
string theReply = "Thank you for your message" + data.Length.TOString() + " characters...I'm the Body!!!";
byte[] msg = Encoding.ASCII.GetBytes(theReply);
handler.Send(msg);
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}Решение задачи: «Мне код сервера исправить немного»
textual
Листинг программы
IPAddress myIP;
Console.WriteLine("говори адрес");
while(!IPAddress.TryParse(Console.ReadLine(), out myIP))
{
Console.WriteLine("ысчо разок попробуй");
}
Console.WriteLine(myIP.ToString());
Console.ReadKey(true);