Click here to Skip to main content
Click here to Skip to main content

Send Data to remote machine using IPV6/IPV4 based address

, 29 Apr 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
send data to other system using two different ways, one way using IPV6 and other way is IPV4.


Receive IPV6 or IPV4 based Data Using C# in this article I explained how to receive IP6 or IP4 data. Now i am going to explain how to send data using IPv6 or IPv4 address.

IPV4 address is a 32 bit numeric address is written in decimal ad four numbers separated by dot. for example :

IPV6 address is a 128 bit written in hexadecimal and separated by colon. for example : fe80:cft7:b16:2817:b24a:1dd7

TO Know more about IPv6 and IPv4. Please refer following Links

  1. IPV6
  2. IPV4
  3. IPv6 vs IPv

Below screen explains about how to send data using IPV4 address

In our sample i am using port 95 to send and receive data between machines. To send data i developed a WPF application. Main screen contains three text box's and one button.

  1. first textbox for IP address
  2. second text box for Port
  3. for message.
  4. button used to accept text boxs and send data to remove machine.

Below screen explain about send data via IPV6 address.

Below is output screen of receiving TCP based data reference(Receive IPV6 or IPV4 based Data Using C#)

Using the code

Below code is the main login to send data to remove machines using IPV6 or IPV4 based data. I used System.Scocket.System.Net.Sockets

                //Preparing/Converting String based ipaddress+port to  Class IPEndPoint
                IPEndPoint ipeh = new IPEndPoint(IPAddress.Parse(ipaddress), Convert.ToInt32(port));

                Socket connection;
                if (isIPv6Address) // USED IPV6 Address to send data
                    //Creating object to socket based of type of the IP address used.
                    connection = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

                {// USED IPV4 Address to send data
                    //Creating object to socket based of type of the IP address used.
                    connection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                //Establish a connection with remove machine
                //Convert string based message into bytes format.
                byte[] messageinbytes = System.Text.ASCIIEncoding.ASCII.GetBytes(msg);
                //Send bytes over the network.
                //Close the scocket connection.

            catch (Exception ex)
                throw (ex);

In the above code i used AddressFamily.InterNetwork parameter while create Socket. AddressFamily.InterNetwork means IPv4 based address. where AddressFamily.InterNetworkV6 means IPv6 based address.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

QuestionIf clients and server will not on same network. i mean not on LAN network.. PinmemberTariq Mehmood28-Nov-14 3:25 
Questionwhile i am trying to Use your sample,i am getting Error PinmemberTariq Mehmood28-Nov-14 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150302.1 | Last Updated 29 Apr 2014
Article Copyright 2014 by munagalasantosh
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid