You are on page 1of 1

using System;

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

namespace server_3
{
class Program
{
private const int BUFFER_SIZE = 1024;
private const int PORT_NUMBER = 1000;
static ASCIIEncoding encoding = new ASCIIEncoding();
static void Main(string[] args)
{
int sum = 0;
int mul = 1;
try
{
IPAddress address = IPAddress.Parse("127.0.0.1");
TcpListener listener = new TcpListener(address, PORT_NUMBER);
listener.Start();
Console.WriteLine("Server bat dau " + listener.LocalEndpoint);
Console.WriteLine("Cho trong giay lat...");

Socket socket = listener.AcceptSocket();


Console.WriteLine("Connection received from " +
socket.RemoteEndPoint);

byte[] data = new byte[BUFFER_SIZE];


socket.Receive(data);

string str = encoding.GetString(data);


string[] strS = str.Split(' ');
for (int i = 0; i < strS.Length; i++)
{
sum += int.Parse(strS[i]);
mul *= int.Parse(strS[i]);
}
socket.Send(encoding.GetBytes("Tong = " + sum.ToString() + "\nTich"
+ mul.ToString()));
} catch
{

}
}
}

You might also like