从gprs接收数据为 。请帮忙解决这个问题。 [英] Receiving the data from gprs as �. Please help to solve this.
本文介绍了从gprs接收数据为 。请帮忙解决这个问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在接收由GPRS设备发送的IP59.92.111.69的数据,但我没有收到正确的数据。我收到的数据只是问号( )。请帮我找到解决方案。
这是我的编码。
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Net.WebSockets;
使用 System.Net.Sockets;
使用 System.Net;
使用 System.Text;
使用 System.Threading.Tasks;
命名空间 TCP_IP_Client
{
public partial class client:System.Web.UI.Page
{
System.Net.Sockets.TcpClient clientsocket = new System.Net.Sockets.TcpClient();
受保护 void Page_Load( object sender,EventArgs e)
{
clientsocket.Connect( 59.92。 111.69, 8080 );
Label1.Text = 服务器连接;
}
受保护 void Button1_Click(< span class =code-keyword> object sender,EventArgs e)
{
NetworkStream serverStream = clientsocket.GetStream();
// byte [] outStream = System.Text.Encoding.ASCII.GetBytes(TextBox2.Text + $);
// serverStream.Write(outStream,0,outStream.Length) ;
// serverStream.Flush();
< span class =code-keyword> byte [] inStream = new byte [< span class =code-digit> 10025 ];
serverStream.Read(inStream, 0 ,( int )clientsocket.ReceiveBufferSize);
Response.Write(clientsocket.ReceiveBufferSize);
string returndata = System.Text.Encoding.UTF7.GetString(inStream);
// string returndata = System.Text.Encoding.UTF32.GetString(inStream);
// s.Length.ToString();
msg(returndata) ;
TextBox2.Text = ;
TextBox2.Focus();
}
public void msg(< span class =code-keyword> string mesg)
{
TextBox1.Text = Environment.NewLine + 和 + mesg;
}
}
}
我尝试过:
我尝试过编码格式ASCII,UTF32,UTF7,UTF8和默认编码方法。
解决方案
);
// serverStream.Write(outStream,0, outStream.Length);
// serverStream.Flush();
byte [] inStream = new byte [ 10025 ];
serverStream.Read(inStream, 0 ,( int )clientsocket.ReceiveBufferSize);
Response.Write(clientsocket.ReceiveBufferSize);
string returndata = System.T ext.Encoding.UTF7.GetString(插播广告);
// string returndata = System.Text.Encoding.UTF32.GetString(inStream);
// s.Length.ToString();
msg(returndata) ;
TextBox2.Text = ;
TextBox2.Focus();
}
public void msg(< span class =code-keyword> string mesg)
{
TextBox1.Text = Environment.NewLine + 和 + mesg;
}
}
}
我尝试过:
我尝试过编码格式ASCII,UTF32,UTF7,UTF8和默认编码方法。
什么让你认为这是一个编码问题?
这里的快速检查说没有返回真正的数据:数据缓冲区充满了空白。
所以检查你的IP地址,检查远程端,检查你的数据。
并且......看你的尺寸:默认的接收缓冲区大小比你分配的缓冲区大得多! / BLOCKQUOTE>
I am receiving data from the IP "59.92.111.69" which is sent by an GPRS device, but i am not getting correct data. The data which i am receiving is only question mark("�"). Please help me to find the solution.
Here is my coding.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net.WebSockets; using System.Net.Sockets; using System.Net; using System.Text; using System.Threading.Tasks; namespace TCP_IP_Client { public partial class client : System.Web.UI.Page { System.Net.Sockets.TcpClient clientsocket = new System.Net.Sockets.TcpClient(); protected void Page_Load(object sender, EventArgs e) { clientsocket.Connect("59.92.111.69", 8080); Label1.Text = "Server connected"; } protected void Button1_Click(object sender, EventArgs e) { NetworkStream serverStream = clientsocket.GetStream(); // byte[] outStream = System.Text.Encoding.ASCII.GetBytes(TextBox2.Text + "$"); //serverStream.Write(outStream, 0, outStream.Length); //serverStream.Flush(); byte[] inStream = new byte[10025]; serverStream.Read(inStream, 0, (int)clientsocket.ReceiveBufferSize); Response.Write(clientsocket.ReceiveBufferSize); string returndata = System.Text.Encoding.UTF7.GetString(inStream); //string returndata = System.Text.Encoding.UTF32.GetString(inStream); //s.Length.ToString(); msg(returndata); TextBox2.Text = ""; TextBox2.Focus(); } public void msg(string mesg) { TextBox1.Text = Environment.NewLine + " and " + mesg; } } }
What I have tried:
I have tried the encoding formats ASCII, UTF32, UTF7, UTF8 and default encoding methods.解决方案"); //serverStream.Write(outStream, 0, outStream.Length); //serverStream.Flush(); byte[] inStream = new byte[10025]; serverStream.Read(inStream, 0, (int)clientsocket.ReceiveBufferSize); Response.Write(clientsocket.ReceiveBufferSize); string returndata = System.Text.Encoding.UTF7.GetString(inStream); //string returndata = System.Text.Encoding.UTF32.GetString(inStream); //s.Length.ToString(); msg(returndata); TextBox2.Text = ""; TextBox2.Focus(); } public void msg(string mesg) { TextBox1.Text = Environment.NewLine + " and " + mesg; } } }
What I have tried:
I have tried the encoding formats ASCII, UTF32, UTF7, UTF8 and default encoding methods.
What makes you think it's an encoding problem?
A quick check here says there is no real data being returned: the data buffer is full of nulls.
So check your IP address, check the remote end, check your data.
And...watch your sizes: the default receive buffer size is considerably larger than the buffer you have allocated!
这篇关于从gprs接收数据为 。请帮忙解决这个问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文