HI friends her my code i want to correct this code please help me
thanks and i want to connect or read multiple client at a time

using System;
using System.IO;
using System.Net.Sockets;
using System.Text;
namespace SocketConsoleclient

{
     class Program
     {
        static void Main()
        {
        byte[] receivedBytes = newbyte[1024];
        IPHostEntry ipHost = Dns.Resolve("127.0.01");
        IPAddress ipaddress = ipHost.AddressList[0];
        IPEndpoint ipEndPoint = new IPEndPoint(ipAddress, 2112);
        Console.Writeline("Starting: Creating Socket Object");

        Socket sender = new socket (AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
        sender.connect(ipEndPoint);
        Console.Writeline("SucessFully connected to {0}",
        sender.RemoteEndPoint);
        stringsendingMessage  ="Hello World Socket Test";
        Console.Writeline("Creating Message : Hello world Socket Test");
        byte[] forwardMessage = Encoding.ASCII.GetBytes(sendingMessage + "[FINAL]");
        sender.send(forwardMessage);
        int totalBytesReceived = sender.Receive(receivedBytes);
        Console.Writeline("Message provide from server: {0},Encoding.ASCII.Get.String(receivedBytes,0, totalBytesReceived)");
        sender.Shutdown(SocketShutdown.Both);
        sender.close();
        Console.Readline();
        }
        }
        }

Recommended Answers

All 2 Replies

Use [code] tags to post source code. Try to implement thread.

You could also use the asynchronous methods of the sockets to accomplish this:

socket.BeginConnect();
        socket.BeginSend();

An extensive implementation of using asynchronous TCP/IP sockets and the thread pool was given in this thread:
http://www.daniweb.com/forums/thread228973.html

You could modify that application to send string messages instead of files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.