Jump to content
  • Advertisement
Sign in to follow this  
Matthew Grant

Socket Connect Error

This topic is 1598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Howdy Folks!

I've been having this really odd error. I cannot seem to identify what it is, if you wouldn't mind giving me a little help here It would be much appreciated!

      public void MiscCommand(string cmd, string target)
        {
            Socket cn = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            byte[] data = Encoding.ASCII.GetBytes(cmd);
            cn.Connect(target, 7772); // target is the string containing the target IP for the message
            cn.Send(data);
            Log("Sent: " + cmd + " to IP:" + target);
            cn.Close();
        }

The Error I am picking up is simply this:

relating to "target"
Specified argument was out of the range of valid values.
Parameter name: The size of hostName is too long. It cannot be longer than 126 characters.

Even though the string is only "192.168.1.2"

What's the dealio guys!? is it just returning this because it is not being picked up by the client or what?

Much appreciated!

 

Also, I'm using .NET Framework 3.5

P.S If I manually put in the IP Address it works perfectly, it just does not appear to be working with the 'target' string..

 

I also used DNS.GetHostByAddress(target) but that is reporting "An invalid IP address was specified." even though if I manually put in the IP it

It may be something to do with the Encoding.ASCII.GetString(_cbuffer), it might be generating invisible whitespace - yep that was it

 

edit: It's working, the buffering string I received had a massive byte length and I just had to Isolate the IP from the surrounding whitespace. :P

Edited by MattyG08

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!