RT,谁有例子发链接也行,发代码也行!
解决方案 »
- 麻烦,请高手帮我解释一下这个代码啊。谢谢
- GRIDVIEW控件显示不出来
- 什么简单的方法可以根据两个List中的对象属性,求两个List 的并集?
- 填充水晶报表的时候 为什么我查询的dataset 不起作用?急
- c#winform程序打包后在本机运行正常,在别人机器总是提示"SQL Server不存在或访问被拒绝"
- 问个简单问题!!什么是强类型编程!!
- 在dropdownlist中快速寻找内容
- 设置 DataSource 属性后无法修改项集合。
- C#如何执行一个外部的exe文件?
- 请问在c#中,接口和抽象类是什么意思,通常是派什么用处的
- 飞信是用c#做的吗?
- 接收邮件时汉字出现乱码(不可解码)
static void Connect(String server, String message)
{
try
{
// Create a TcpClient.
// Note, for this client to work you need to have a TcpServer
// connected to the same address as specified by the server, port
// combination.
Int32 port = 13000;
TcpClient client = new TcpClient(server, port);
// Translate the passed message into ASCII and store it as a Byte array.
Byte[] data = System.Text.Encoding.ASCII.GetBytes(message); // Get a client stream for reading and writing.
// Stream stream = client.GetStream();
NetworkStream stream = client.GetStream(); // Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length); Console.WriteLine("Sent: {0}", message); // Receive the TcpServer.response.
// Buffer to store the response bytes.
data = new Byte[256]; // String to store the response ASCII representation.
String responseData = String.Empty; // Read the first batch of the TcpServer response bytes.
Int32 bytes = stream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
Console.WriteLine("Received: {0}", responseData); // Close everything.
stream.Close();
client.Close();
}
catch (ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: {0}", e);
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
Console.WriteLine("\n Press Enter to continue...");
Console.Read();
}
该程序是C#语言实现的,对学习Socket通讯是不错的帮助