Advertisement Jump to content
Sign in to follow this  
Matthew Grant

Socket Connect Error

This topic is 1669 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
            Log("Sent: " + cmd + " to IP:" + target);

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 ""

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!