日期:2014-05-19  浏览次数:20889 次

socket与设备进行http通信发送的控制信息需要加http包头吗?
IPAddress[]   ipa   =   Dns.GetHostAddresses( "192.168.1.126 ");
                        IPEndPoint   ipe   =   new   IPEndPoint(ipa[0],   80);
                        Socket   ipc   =   new   Socket(AddressFamily.InterNetwork,   SocketType.Stream,   ProtocolType.Tcp);
                        string   tobesend   =   "ipcam   console   admin:123456\r\n ";//说明书上用此字符串连接设备,我使用以后不成功,receive了256个0.如果直接用video   show   resolution(此为控制台命令,返回设备视频的格式)则返回一串什么http   method <video> 不成功的说明.我的问题是,与设备进行http通信,难道只是建立socket连接就可以直接发送字符串命令而不用加http包头了吗?意思就是string   tobesend直接被赋成 "ipcam   console   ab:ab\r\n "而不加什么包头?                          
                        byte[]   bytesend   =   Encoding.ASCII.GetBytes(tobesend);
                        Byte[]   byteget   =   new   Byte[256];

                                ipc.Connect(ipe);

                                if   (ipc.Connected)
                                {
                                        ipc.Send(bytesend,   bytesend.Length,   0);

                                        int   num   =   0;
                                        string   result   =   " ";
                                        do
                                        {
                                                num   =   ipc.Receive(byteget,   byteget.Length,   0);
                                                result   =   result   +   Encoding.ASCII.GetString(byteget,   0,   num);
                                        }   while   (num   >   0);
                                        Console.WriteLine( "result   is: "   +   result);
                                        Console.ReadLine();