System.Net.Sockets.SocketException:“以一种访问权限不允许的方式做了一个访问套接字的尝试。”

qq_35305161 2017-07-05 10:39:13
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Net;
using System.Net.Sockets;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//IPAddress ip = new IPAddress(new byte[] { 127, 0, 0, 1 });
IPAddress ip = IPAddress.Parse("127.0.0.1");
//IPAddress ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];

TcpListener tlistener = new TcpListener(ip, 1433);
tlistener.Start();
Console.WriteLine("服务器监听启动......");
while (true)//看上去是死循环,由于阻塞方法,大部分时间都在等待
{
TcpClient remoteClient = tlistener.AcceptTcpClient();//接收已连接的客户端,阻塞方法
Console.WriteLine("客户端已连接!local:{0}<---Client:{1}", remoteClient.Client.LocalEndPoint, remoteClient.Client.RemoteEndPoint);
}

//ConsoleKey key;
//do
//{
// key = Console.ReadKey(true).Key;
//}
//while (key != ConsoleKey.Q);
}
}
}
...全文
1186 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
TonyTonyQ 2017-07-06
  • 打赏
  • 举报
回复 1
你本机是否安装了SQL Server? 1433是SQL Server的监听端口,估计是端口冲突导致错误。
qq_35305161 2017-07-05
  • 打赏
  • 举报
回复
到底是怎么回事啊?有没有大佬教教我!
私聊与多聊、TCP运用 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.Net.Sockets; using System.Net; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.IO; using System.Collections; using System.Collections.Specialized; namespace EasyChatServer { class Listener { #region 字段定义 /// /// 服务器程序使用的端口,默认为8888 /// private int _port = 8888; /// /// 接收数据缓冲区大小64K /// private const int _maxPacket = 64 * 1024; /// /// 服务器端的监听器 /// private TcpListener _tcpl = null; /// /// 保存所有客户端会话的哈希表 /// private Hashtable _transmit_tb = new Hashtable(); #endregion #region 服务器方法 /// /// 关闭监听器并释放资源 /// public void Close() { if (_tcpl != null) { _tcpl.Stop(); } //关闭客户端连接并清理资源 if (_transmit_tb.Count != 0) { foreach (Socket session in _transmit_tb.Values) { session.Shutdown(SocketShutdown.Both); } _transmit_tb.Clear(); _transmit_tb = null; } } /// /// 配置监听端口号 /// public void GetConfig() { string portParam; Console.Write("请输入监听端口,直接回车则接受默认端口8888: "); portParam = Console.ReadLine(); if (portParam != string.Empty) { if (!int.TryParse(portParam, out _port) || _port 65535) { _port = 8888; Console.WriteLine("端口号不合法,默认端口号被接受!");

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧