Socket通讯一个灰常简单得小栗子。~~~
服务器端:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;
namespace ConsoleApplication
{
class Program
{
private static byte[] result = new byte[1024];
private static int myProt = 8888; //端口
static Socket serverSocket;
static SqlTool st = new SqlTool();//数据库操作工具类
static void Main(string[] args)
{
//服务器IP地址
IPAddress ip = IPAddress.Parse("192.168.1.88");
serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
serverSocket.Bind(new IPEndPoint(ip, myProt)); //绑定IP地址:端口
serverSocket.Listen(10); //设定最多10个排队连接请求
Console.WriteLine("启动监听{0}成功", serverSocket.LocalEn