PDA

View Full Version : سوال: مشکل در استفاده از حلقه LOOP



parsuser
چهارشنبه 14 دی 1390, 01:30 صبح
سلام من میخوام این برنامه (کلاینت،سرور )در حلقه بزارم .از برنامه نویسی هم چیز زیادی نمیدونم

کارش یه ارسال ودریافت سادس ،میخوام کاری بکنم که کارشونا تکرار کنند وقطع نشند مثل چت.
اساتید راهنمایی کنند.

کلاینت :



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{

Socket s1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress serverAddress = IPAddress.Parse("127.0.0.1");


IPEndPoint serverPoint = new IPEndPoint(serverAddress, 1400);
s1.Connect(serverPoint);
Console.WriteLine("connected");

byte[] sendbyte = Encoding.ASCII.GetBytes(Console.ReadLine());
s1.Send(sendbyte);
byte[] rcvbyte = new byte[5000];
s1.Receive(rcvbyte);

Console.WriteLine(Encoding.ASCII.GetString(rcvbyte ));

Console.ReadLine();


}
}
}




سمت سرور :




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{



Socket sServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint myPoint = new IPEndPoint(IPAddress.Any, 1400);
sServer.Bind(myPoint);
Console.WriteLine("waiting for a connection");
sServer.Listen(5);
Socket accept = sServer.Accept();
Console.WriteLine("accpeted");

byte[] rcvbyte = new byte[5000];
accept.Receive(rcvbyte);

Console.WriteLine(Encoding.ASCII.GetString(rcvbyte ));

byte[] sendbyte = Encoding.ASCII.GetBytes(Console.ReadLine());
accept.Send(sendbyte);

Console.ReadLine();

}
}
}