Socket,局域网内发送数据时,在XP环境下测试正常,但是在win2003下测试提示“未知主机”
public void send(string IP, string Txt)
{
//string hostName = IP;
int port = Int32.Parse("8899");
//IPHostEntry ipInfo = Dns.GetHostEntry(hostName);
//IPAddress[] ipAddr = ipInfo.AddressList;
//IPAddress ip = ipAddr[0];
IPEndPoint hostEP = new IPEndPoint(IPAddress.Parse(IP), port);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
socket.Connect(hostEP);
}
catch (Exception se)
{
System.Web.HttpContext.Current.Response.Write("连接错误" + se.Message);
}
string sendStr = Txt;
byte[] bytesSendStr = new byte[1024];
bytesSendStr = Encoding.ASCII.GetBytes(sendStr);
try
{
socket.Send(bytesSendStr, bytesSendStr.Length, 0);
}
catch (Exception ce)
{ System.Web.HttpContext.Current.Response.Write("发送错误:" + ce.Message);
}
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}请高手帮我看,这是代码的问题。还在在2003下要做一些相应的设置。
public void send(string IP, string Txt)
{
//string hostName = IP;
int port = Int32.Parse("8899");
//IPHostEntry ipInfo = Dns.GetHostEntry(hostName);
//IPAddress[] ipAddr = ipInfo.AddressList;
//IPAddress ip = ipAddr[0];
IPEndPoint hostEP = new IPEndPoint(IPAddress.Parse(IP), port);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
socket.Connect(hostEP);
}
catch (Exception se)
{
System.Web.HttpContext.Current.Response.Write("连接错误" + se.Message);
}
string sendStr = Txt;
byte[] bytesSendStr = new byte[1024];
bytesSendStr = Encoding.ASCII.GetBytes(sendStr);
try
{
socket.Send(bytesSendStr, bytesSendStr.Length, 0);
}
catch (Exception ce)
{ System.Web.HttpContext.Current.Response.Write("发送错误:" + ce.Message);
}
socket.Shutdown(SocketShutdown.Both);
socket.Close();
}请高手帮我看,这是代码的问题。还在在2003下要做一些相应的设置。
解决方案 »
- 一个严峻的C#问题
- C#中listview的数据怎样更新啊?
- 【请教】label控件设置为透明时切换窗体或者最大化后恢复时label控件闪烁得比较厉害,请问有什么办法解决。
- gridview提取信息问题?
- 如何使datagridview的每个单元格里的文字居中显示
- 在C#中如何用变量名中内容替换变量名的一部分(急)
- String 與 sting 有何區別?
- sql server的windows集成认真如何实现的?
- Winform treeview 点击子节点跳转窗体弹出两个窗体
- C# 第一次提问 。
- 面试题,有答案但是没看懂?能帮忙解释下吗?谢谢!
- datatable筛选列组成新的datatable
[email protected]
然后估计就是你的IP地址有问题。