4
Answers

Sockets Class, Windows Forms.

Michael Wilson

Michael Wilson

14y
2.7k
1
Hi, I'm trying to write a program to control an external device (connection via crossover cable).
It isn't throwing me any errors but the device is not changing it's setting (I've triple checked the skippy codes). Anyone able to take a look and give me any suggestions would be greatly appreciated.

The connection is initialised as a result of a yes/no message box.

Here is the code:
 

                    case DialogResult.Yes:

 

                        // "Yes" processing

                        IPAddress ia = IPAddress.Parse(ipAddress);

                        IPEndPoint ie = new IPEndPoint(ia, 5555);

 

Socket sock1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

 

                        try

                        {

                            sock1.Connect(ie);

                        }

 

                        catch (SocketException e)

                        {

                            string error = e.ToString();

                            MessageBox.Show(error, "Problem connecting to host!",

                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);

                            sock1.Shutdown(SocketShutdown.Both);

                            sock1.Close();

                            return;

                        }

 

                        try

                        {

                            string fMessage = "OUTPut:SQUelch ON";

                            Encoding ASCII = Encoding.ASCII;

                            Byte[] ByteGet = ASCII.GetBytes(fMessage);

                            sock1.Send(ByteGet, ByteGet.Length, 0);

 

 

 

                            MessageBox.Show("Did Squelch change?", "Check.",

                            MessageBoxButtons.OK, MessageBoxIcon.Warning);

 

                            sock1.Shutdown(SocketShutdown.Both);

                            sock1.Close();

                                                       

                        }

                        catch (SocketException e)

                        {

                            string error = e.ToString();

                            MessageBox.Show(error, "Problem communicating to host!",

                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);

                            sock1.Shutdown(SocketShutdown.Both);

                            sock1.Close();

                            return;

                        }

 

                        break;


Answers (4)