I am trying to send a tcp message to a gprs server. I was trying to do it through WCF, however, I always see tutorials or information regarding the consumption of services, however, there is no service to consume. It is simply sending a tcp-type message to a server using WCF. I have the port, and the server for the connection. How could I do it? I need to create the WCF client for sending messages, but I don't know how without services.
I am using visual studio and c # language
I am trying to send a tcp message to a gprs server. I was trying to do it through WCF
Since the remote server is not a SOAP service but simply a server exposing a TCP port you should use TCP APIs rather than WCF. The reason being that message content and protocol will be different. WCF uses SOAP messages which generally are sent as XML text as opposed to TCP which is binary. Now you could configure WCF to serialize as binary but the result will still be different. There are alot more differences to TCP vs WCF which I won't go into here.
Use the following TCP example:
TcpClient client = new TcpClient("localhost", 80); //enter your server ip and port
// Translate the passed message into ASCII and store it as a Byte array
Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
// Get the stream for writing
NetworkStream stream = client.GetStream();
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
//Close everything to avoid memory leaks
stream.Close();
client.Close();