Hello,
I want to send data to server the problem is only the first data is sent .
server code:
- namespace Server
- {
- class Program
- {
- static byte[] Buffer { get; set; }
- static Socket sck;
- static void Main(string[] args)
- {
- sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- sck.Bind(new IPEndPoint(0, 2000));
- sck.Listen(100);
- Socket accepted = sck.Accept();
- Buffer = new byte[accepted.SendBufferSize];
- int bytesRead = accepted.Receive(Buffer);
- byte[] formatted = new byte[bytesRead];
- for (int i = 0; i < bytesRead; i++)
- {
- formatted[i] = Buffer[i];
- }
- string strData = Encoding.ASCII.GetString(formatted);
- Console.Write(strData + "\r\n");
- Console.Read();
- sck.Close();
- accepted.Close();
- }
- }
- }
client code:
- namespace Client
- {
- class Program
- {
- static Socket sck;
- static void Main(string[] args)
- {
- sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2000);
- try
- {
- sck.Connect(localEndPoint);
- }
- catch
- {
- Console.Write("Unable to connect to remote end point!\r\n");
- Main(args);
- }
- Console.Write("Your name: ");
- string text = Console.ReadLine();
- byte[] data = Encoding.ASCII.GetBytes(text);
-
- sck.Send(data);
- Console.Read();
- Console.Write("Your age: ");
- string text1 = Console.ReadLine();
- byte[] data1 = Encoding.ASCII.GetBytes(text1);
-
- sck.Send(data1);
- Console.Write("Data Sent!\r\n");
- Console.Write("Press any key to continue...");
- Console.Read();
- sck.Close();
- }
- }
- }