Sign in to follow this  
Matthew Grant

Socket Connect Error

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this