-1

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();
        }
        }
        }

Edited by Dani: Formatting fixed

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by sknake
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.