SOCKET编程资料

来源:百度知道 编辑:UC知道 时间:2024/05/23 13:02:39
我要资料,实例,只要关于SOCKET的都要

我选第一个题目,这是服务器端,用c#实现的(VS2005):
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Threading;
using System.Net.Sockets;

namespace conNetWorkServer
{
class Program
{
static void Main(string[] args)
{
Socket client;
Socket ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
byte[] addbyte = { 127, 0, 0, 1 };
IPEndPoint add = new IPEndPoint(new IPAddress(addbyte), 5050);
ServerSocket.Bind(add);
ServerSocket.Listen(3);

while (true)
{
Thread.Sleep(100);
if ((client = ServerSocket.Accept()) != null)
{
Console.WriteLine("连接上...发送数据....");
byte[] message = { 49, 50, 51, 52, 53, 54, 0 };
client.Send(message);
Console.WriteLine("结束.")
client.Close();
break;
}

}

}
}