creating a tcp header c# -
i communicating application requires custom tcp header, may me on how send one, have tried following failing
public string sendrequest(string destinationurl, string requestxml, int timeout) { byte[] tcpheader = new utf8encoding().getbytes(createtcpheader(requestxml)); byte[] bytestosend = new utf8encoding().getbytes(requestxml); tcpclient client = new tcpclient("127.0.0.1", 23001); networkstream nwstream = client.getstream(); //console.writeline("sending : " + data); nwstream.write(tcpheader, 0, tcpheader.length); nwstream.write(bytestosend, 0, bytestosend.length); byte[] bytestoread = new byte[client.receivebuffersize]; int bytesread = nwstream.read(bytestoread, 0, client.receivebuffersize); // console.writeline("received : " + new utf8encoding().getstring(bytestoread, 0, bytesread)); // console.readline(); client.close(); return (new utf8encoding().getstring(bytestoread, 0, bytesread).tostring()); } static string createtcpheader(string data) { //byte[] header; int quotent = data.length / 256; decimal remainder = data.length % 256; byte[] bytequotient = new utf8encoding().getbytes(quotent.tostring()); byte[] byteremainder = new utf8encoding().getbytes(remainder.tostring()); //header = bytequotient.tostring() + byteremainder.tostring(); return bytequotient.tostring() + byteremainder.tostring(); }
Comments
Post a Comment