.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

Sockets and mixing IPV4 and IPV6

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :.NET Framework
 

I am creating two applications which communicate via TCP/IP sockets using C# and the .NET sockets library.  Once side create a socket and binds to a hostname and port, the other does a BeginConnect/EndConnect.  When I use both programs on the same machine (Win 7 64-bit) and use the hostname "localhost" and AddressFamily InterNetworkV6, everything is fine.

When I put the listener (the one binding to a port and listening) on a Win XP 32-bit machine, I can only create a socket if the AddressFamily is InterNetwork (IPV4).  It runs and waits for a connection, but on the Win7 machine, when I do the BeginConnect, I get an error:

19673 [10] ERROR CardioInsight.Athena.RMFInterface.CommState.Connecting (null) -
 BeginConnect() fails
System.Net.Sockets.SocketException (0x80004005): The system detected an invalid
pointer address in attempting to use a pointer argument in a call
   at System.Net.Sockets.Socket.DoBeginConnect(EndPoint endPointSnapshot, Socket
Address socketAddress, LazyAsyncResult asyncResult)
   at System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback ca
llback, Object state)
   at CardioInsight.Athena.RMFInterface.ClientNetworkInterface.BeginConnect(Asyn
cCallback callback, Object state) in C:\CardioInsight\Athena\trunk\Code\Car


View Complete Post


More Related Resource Links

Receiving ipv6 message with raw sockets

  

I am trying to receive a message along with its layer 3 (IPv6) and layer 4 (UDP) headers using raw sockets in C#.

The problem is that I receive 8 bytes of data before the ipv6 header and I don't know what they represent

In wireshark, I don't see these bytes.

If I use a similar code for Ipv4, everything works ok (no extra bytes before the Ipv4 header)

 

Do you have any idea?

 

Thanks!

 

This is the message that I receive :

 

the extra bytes : 01 04 b6 6a 00 00 00 00

the ipv6 header : 60 00 00 00 00 0b 11 40 fe 80 00 00 00 00 00 00 02 15 17 ff fe d7 ed 94 fe 80 00 00 00 00 00 00 99 a8 3d 54 5c 78 9f f4

the udp header: bd c4 27 0f 00 0b 45 6c 

my payload : ff aa ff

 

 

This is the code that I use for capturing the packets:

 

using System;

using System.Net;

using System.Net.Sockets;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.IO;

 

 

namespace Ipv6Utils

{  

    class Program

    {

        private byte[] byteData = new byte[4096];

        p

Regex pattern for validating IPv6

  

Can anyone can make a regular expression pattern for validating IPv6 (not IPv4)?

Ipv6 has many formats and aliases. I tried making the pattern but written in a lot of codes (i'm not sure my code below will be 100% accepting valid formats and 100% declines invalid formats).

(([0-9a-fA-F]{1,4}:){1,1}(:[0-9a-fA-F]{1,4}){1,6})
|
(([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5})
|
(([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4})
|
(([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3})
|
(([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2})
|
(([0-9a-fA-F]{1,4}:){1,6}(:[0-9a-fA-F]{1,4}){1,1})
|
((([0-9a-fA-F]{1,4}:){1,7}|:):)
|
(:(:[0-9a-fA-F]{1,4}){1,7})
|
(((([0-9a-fA-F]{1,4}:){6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}))
|
((([0-9a-fA-F]{1,4}:){5}[0-9a-fA-F]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}))
|
(([0-9a-fA-F]{1,4}:){5}:[0-9a-fA-F]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,1}(:[0-9a-fA-F]{1,4}){1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,3}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,2}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9

Test Run: WCF Service Testing with Sockets

  

There are many ways to test WCF services, but the socket-based approach is flexible and very useful for security and performance testing. We show you show you how to test a WCF service using a network socket based approach.

James McCaffrey

MSDN Magazine February 2010


The Polyglot Programmer: Mixing And Matching Languages

  

See why you need to be a polyglot programmer and what mixing and matching languages can do for your projects.

Ted Neward

MSDN Magazine March 2009


Winsock: Get Closer to the Wire with High-Performance Sockets in .NET

  

The Win32 Windows Sockets library (Winsock) provides mechanisms to improve the performance of programs that use sockets, and the Microsoft .NET Framework provides a layer over Winsock so that managed applications can communicate over sockets. To use all these layers to write a truly high-performance socket-based application requires a little background information, as Daryn Kiely explains here.

Daryn Kiely

MSDN Magazine August 2005


Secure Sockets Layer: Protect Your E-Commerce Web Site with SSL and Digital Certificates

  

Security is one of the most important factors in the future growth of e-businesses. Making sure that communications remain secure between customers and the Web server is a critical issue. Secure Sockets Layer (SSL) is the standard that secure Web sites are built upon today. This article presents an overview of SSL-based Web security, explaining such fundamental concepts as digital certificates and their distribution, encryption, and the proper configuration of Microsoft Internet Information Services (IIS). Acquiring a certificate, installing it, and configuring IIS for SSL are outlined in a step-by-step process.

John Papa

MSDN Magazine April 2001


Windows Sockets 2.0: Write Scalable Winsock Apps Using Completion Ports

  

Writing a network-aware application isn't difficult, but writing one that is scalable can be challenging. Overlapped I/O using completion ports provides true scalability on Windows NT and Windows 2000. Completion ports and Windows Sockets 2.0 can be used to design applications that will scale to thousands of connections. The article begins with a discussion of the implementation of a scalable server, discusses handling low-resource, high-demand conditions, and addresses the most common problems with scalability.

Anthony Jones and Amol Deshpande

MSDN Magazine October 2000


Sending TelNet Sockets?

  

How can i send TelNet sockets through aspx.cs code?

like sending sockets through PuTTy...


is it possible?


An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in system.dll

  
Additional information: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respondThis error occurs when i was executing a vc++.net program implementing ICMP....Error occurs when executing this statement... iRet=st->ReceiveFrom(RecvByte,RecvByte->Length,SocketFlags::None,&senderRemote);How to solve this problem????

Can I use TCP sockets within managed funcs, triggers and stored procedures?

  
I have seen nothing prohibiting this, but have not yet had time to write some test code. Does anyone know for sure if SQL Server 2008 prohibits or allows TCP sockets for communications, inside a C# SQL/CLR function or method? I guess it must because this is implict when creating data connections and so on, which are obvioulsy allowed. Thanks Cap'n  

Configuring SQL Server 2005 to use only IPv6

  
Hi, I need to configure my SQL Server 2005 Express to use only IPv6. I understand this is done in the Configuration Manager but do not know exactly where. Can someone kindly advise? Thank you.

Issues regarding sockets (stopping receiving packets).

  
Hello, I've created a server for my game, but for some unknown reason the server (most likely) stops receiving packets while the client still tries to send them. I've tried to use a couple examples from MSDN, but it still just stops receiving. This is what I think that happens: Client connects to server Server sends packets as response Client responds to those packets Server sends a lot of packets (one packet at a time) Client tries to send packet, but it kinda fails (it does send packets though!) Server waits (doesn't get any packet anymore) Client triggers timeout code on the server side and gets disconnected from the server Does anyone have an idea how and why this can happen? Here are the receive functions I use: BeginReceive (SocketInfo includes data such as amount of data to receive, state of packet (header or content) and the buffer) public void BeginReceive(SocketInfo socketInfo) { if (mDisconnected != 0) return; try { args = new SocketAsyncEventArgs(); args.Completed += (s, a) => EndReceive(a); args.UserToken = socketInfo; args.SetBuffer(socketInfo.DataBuffer, socketInfo.Index, socketInfo.DataBuffer.Length - socketInfo.Index); if (args != null) { try { if (!Socket.ReceiveAsync(args)) EndReceive(args); } catch (ObjectDisposedException) { Disconnect(); return; }

.NET Sockets and the firewall.

  
I've written a fairly simple tool that opens a socket and waits for requests. Nothing fancy. When I build and run as a tool, my system pops up a dialog needing admin approval. Give it such and the apps runs along handling requests from the network. Great. When I build it as a service it isn't receiving requests. As a test I turned off the firewall. With the firewall off, it's working fine as a service. So the firewall is blocking my service. My question is, what do I need to do when building as a service that allows the port to be open? I've dug through .NET and don't see support for this. What little I've found Googling has all been fairly old (like 5+ years).  Anyone know the right solution?  

Sockets in Windows Forms, Server Hanging

  
First off, I'm relatively new to C# but not programming.  I've written multiple connection apps in VB6 off and on for the last 8 years.  The problem with my server is that it hangs when ChatServer() is called and nothing appears in the rich text box.  I have no idea how to correct this or get it to start listening for connections, accept them, then retrieve data.  Pretty much learning as I go.  Here's the server so far: Any help would be greatly appreciated.   Edit:  I rewrote the server code using Winsock Control 6.0.  I know it's outdated but it's what I know and fairly well.  However, I noticed they did away with control array's!  What in the world?  Instead of setting a control's index property to 0, you now have to create references, objects, etc. etc.  SO much code for something so simple.  Anyway.  The problem now lies with the following code:   namespace Simple_Chat { public partial class frmServer : Form { int maxPlayers = 100; int index; public frmServer() { InitializeComponent(); } public void addToChat(string p, string fntcolor) { switch(fntcolor) { case "red": rtbMain.SelectionColor = Color.Red; rtbMain.SelectedText = p; break; case "blue": rtbMain.Selecti

C# Asynchronous Sockets Problem

  
Dear Programmers, I have some trouble in using Asynchronous Sockets in my application . My C# Window Application Working as Server and several clients to this Server and start data transmitting. Sometimes from a particular  Client i got continues Null Value Client exactly not sending but i m receiving and my application got hang and stop working , What is the problem can any one help me to resolve this problem .   Thanks  JainAmit      

Sockets in Windows Forms, Server Hanging

  
First off, I'm relatively new to C# but not programming.  I've written multiple connection apps in VB6 off and on for the last 8 years.  The problem with my server is that it hangs when ChatServer() is called and nothing appears in the rich text box.  I have no idea how to correct this or get it to start listening for connections, accept them, then retrieve data.  Pretty much learning as I go.  Here's the server so far: Any help would be greatly appreciated.   Edit:  I rewrote the server code using Winsock Control 6.0.  I know it's outdated but it's what I know and fairly well.  However, I noticed they did away with control array's!  What in the world?  Instead of setting a control's index property to 0, you now have to create references, objects, etc. etc.  SO much code for something so simple.  Anyway.  The problem now lies with the following code:   namespace Simple_Chat { public partial class frmServer : Form { int maxPlayers = 100; int index; public frmServer() { InitializeComponent(); } public void addToChat(string p, string fntcolor) { switch(fntcolor) { case "red": rtbMain.SelectionColor = Color.Red; rtbMain.SelectedText = p; break; case "blue": rtbMain.Selecti

PHP 5.3 and IIS 7 - beware of MySQL issues with IPv6

  
I'll keep this short and sweet as it's covered in depth elsewhere. After installing PHP 5.3 suddenly my website stopped working - but instead of throwing errors, it simply sat there and eventually timed out (with no error). Turns out there are issues with both PHP and MySQL around IPv6. The most common solution is "turn off IPv6 support" - not a reassuring answer. On the PHP front, the issue seems to be around fsockopen which works fine in 5.3.0 but not in 5.3.2. The major issue for most people though is that the MySQL driver doesn't properly support IPv6 if you're using a hostname (such as localhost) to connect instead of an IP address, particularly when localhost resolves to "::1". I'm not sure what changed in PHP 5.3.2 to bring this to the surface, but the solution is either to switch to using an IP address, for which there are other good reasons to do so, or modify your hosts file (c:\windows\system32\drivers\etc) and change the line the starts with "::1 localhost" to "#::1 localhost". Hope this helps someone!
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend