Click here to Skip to main content
15,896,383 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I tried to receive the data using TCP/IP technique. I used the TCP client program to receive the data from the IP "59.92.111.69" host "8080".

I can't receive any data. Please suggest me a good technique to receive data from the above ip.

What I have tried:

I tried to receive the data using TCP/IP technique. I used the TCP client program to receive the data from the IP "59.92.111.69" host "8080".

I can't receive any data. Please suggest me a good technique to receive data from the above ip.
Posted
Updated 19-Apr-16 3:38am
Comments
Jochen Arndt 19-Apr-16 9:12am    
What kind of server is listening on 59.92.111.69:8080?

The port number indicates that it may be a HTTP server.

Those will not send data upon connections but reply upon requests. Your client must send a valid request to the server (valid = the server must understand it) and the server will then send a reply.
Garth J Lancaster 19-Apr-16 9:14am    
you dont tell us what the exact issue was, what GPRS device you're communicating with, or show us any code, so how do you expect us to help ?
S.Soundar 20-Apr-16 0:06am    
I have no idea about receiving data from the GPRS device. I don't have any server. I've directly tried TCP Client coding to receive the data but no use.

clientSocket.Connect("59.92.111.69", 8080);

this is how i connected to that ip.

NetworkStream serverStream = clientSocket.GetStream();
TextBox1.Text = TextBox1.Text + "from the receive function";

byte[] inStream = new byte[90025];
int bytesread = serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream, 0, bytesread);
msg(returndata);
serverStream.Flush();

This is what i used to receive data.

I don't know whether this technique is apt to receive data or not. If anyone knows a better way for this please suggest me. Thank you.

1 solution

If it's a standard GPRS modem you need to send it this code after connecting the TCP/IP
GET / HTTP/1.0<cr><lf>
Connection: keep-alive<cr><lf>
<cr><lf>

cr = carriage return (ascii character code 13)
lf = line feed (ascii character code 10)

It wont send you anything until you ask the HTTP server to start sending which is what that does.

It will respond with
HTTP/1.0 200 OK and data will then continue to spew out.

If you think about it you will see why, the GPRS has no way to know when you are ready to receive data after you connect on TCP/IP. Sure you may have connected but you may not be ready to recieve data. Hence you have to initiate the HTTP server to start by sending a command which is what that does and its what a webbrowser does :-)
 
Share this answer
 
v12
Comments
S.Soundar 20-Apr-16 2:23am    
I have no idea about receiving data from the GPRS device. I don't have any server. I've directly tried TCP Client coding to receive the data but no use.

clientSocket.Connect("59.92.111.69", 8080);

this is how i connected to that ip.

NetworkStream serverStream = clientSocket.GetStream();
TextBox1.Text = TextBox1.Text + "from the receive function";

byte[] inStream = new byte[90025];
int bytesread = serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
string returndata = System.Text.Encoding.ASCII.GetString(inStream, 0, bytesread);
msg(returndata);
serverStream.Flush();

This is what i used to receive data.

I don't know whether this technique is apt to receive data or not. If anyone knows a better way for this please suggest me. Thank you.
leon de boer 20-Apr-16 12:26pm    
ClientSocket.Connect("59.92.111.69", 8080); That line there connects to a HTTP server at IP 59.92.111.69 on port 8080. So if that isn't a server then you are wasting your time. So do you know if that is actually a server or not? Where did you get this IP and port from?

So lets assume you misunderstood when you said I don't have a server, and there is a server you are connecting to at that address and you do that via your two lines of code. Now if that isn't a server try ClientSocket.Connect("www.microsoft.com", 80); that will definitely be online we hope :-)

ClientSocket.Connect("59.92.111.69", 8080);
NetworkStream serverStream = clientSocket.GetStream();

Great so now you connected to the HTTP server, so now you need to tell it you want data you do so by writing a command to it and that is the connect string I gave you

if (serverStream.CanWrite){
byte[] myWriteBuffer = Encoding.ASCII.GetBytes("GET / HTTP/1.0/r/nConnection: keep-alive/r/n/r/n");
serverStream.Write(myWriteBuffer, 0, myWriteBuffer.Length);
} else{
Console.WriteLine("Sorry. fix serverStream and make it writable.");
}

Now it will respond back to you. so feel free to run your receive code and you should get a response of "HTTP/1.0 200 OK"

Do you get it you have to write a command, then read its response that it will send you in response for what you asked for.

You can't just listen and try to receive data like you did above you will get nothing. You have to send it a command.

Think like a DOS command line. You type in a command and the OS responds putting stuff to the screen. That is how a HTTP server works you send a command it responds.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900