求助关于C#程序获取udp端口数据的问题
今天用C#取udp端口数据又遇到个问题,数据是取出来了,但是数据一长点,就只能取半截了。完整的应该是以\final\\queryid\1.1结尾,还望各位高手帮忙看看。
源代码如下,运行之后可以直接测试。感谢感谢!!
PS:5555,没分了,只能给20以表感激~~~
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Collections.Specialized;
public partial class server : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int port = 1717;
string host = "222.73.220.41 ";
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip, port);
Socket c = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
c.Connect(ipe);
Console.WriteLine( "connected! ");
string sendStr = "\\info\\ ";
byte[] bs = Encoding.Default.GetBytes( "\\info\\ ");
c.Send(bs, bs.Length, 0);
string recvStr = " ";
byte[] recvBytes = new byte[20000000];
int bytes;
bytes = c.Receive(recvBytes, recvBytes.Length, 0);
recvStr += Encoding.ASCII.GetString(recvBytes, 0, bytes);
recvStr = recvStr.Replace(@ "\final\\queryid\1.1 ", "\\ ");