views:

24

answers:

1

Hello ,My application in c# wants to cominicate with 3rd party Tcp server to send data and recieve back response messages ...The syntax of commands has UShort,ULONG,BYTE type datas a sample command that needed to send by my app is

USHORT 0xFFFF
USHORT 0x00D0
BYTE   0xDD

then in app i send data as

  TcpClient tcpClient = new TcpClient();
       tcpClient.Connect("XX.XX.XX.XX",portnumber);

       Networkstream ns=tcpClient.GetStream();
       StreamWriter sw=new StreamWriter(ns);
       sw.Write(0xFFFF);
       sw.Write(0x00DD);
       sw.Write(0x00);

//or send them bytes

     sw.Write(0xFF);
       sw.Write(0xFF);
       sw.Write(0x00);
       sw.Write(0xD0);
       sw.Write(0x00);
       sw.Write(0x00);

and I read incoming messages over server as

  while (true)
               {

                    byte[] buff=new byte[tcpClient.ReceiveBufferSize];
                    ns.Read(buff, 0, tcpClient.ReceiveBufferSize);
                 string dv= BitConverter.ToString(buff));
                }
//returned data looks like FF-A2-00-23-00-02-00-00-00-00-00-00-D9-2E-20-2E-00-A0-04-00-AE-08
//yes i know this byte syntaxes but returning data is not that i look response for command that i sent..

but returning values are not that i look for Is there any wrong on my code with sending data to server?? and any recomendations on reading writing datas are welcome...

A: 

Nobody can tell you what's wrong with the response when they don't know the protocol employed. The server's sending that because it feels like it... it might be something wrong with your request, or it might be a message indicating that it's offline for service. You can only check it's specification on how to interpret the result it did send, or ask the people who maintain it.

Might also be a good idea to tag this question with the language you're using, so people can make sense of the function calls and whether you're invoking them properly.

I'd also recommend using a packet sniffer (or on Linux simply strace) to show the packets being read and written... you will probably see the mistakes there. Then, use another program to interact with the server that does work, and compare bytes.

Tony
thanks for your reply Tony,I have a documentation that says as explanied on my question sending commands as ushort,ulong or byte type ..I wonder if my command sending as sw.Write(0xFFFF); right for ushort or as sw.Write(0xFF); sw.Write(0xFF); right one? thanks
dankyy1
I used wireshark tcp sniffer to listen network it helped to see what's going on ...
dankyy1