Thread thread1 = new Thread(new ThreadStart(accp1))
thread1.IsBackground = true
thread1.Start()
private void accp1()
{
sfdu = 0
ggg:
accsock1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
myserver1 = new IPEndPoint(myIP, sdkgh)//初始化主机对向(ip和断口)
sock1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)//初始化Socket使用方法不变
sock1.Bind(myserver1)//绑定主机(myserver)是以初始化的首昌主机
sock1.Listen(50)//监听的端口
int t = 1
while (t == 1)
{
try
{
accsock1 = sock1.Accept()//接受客户端的连接请求
if (accsock1.Connected)
{
//this.textBox3.AppendText("与客户端1500建立连接!")
Thread thread1 = new Thread(new ThreadStart(round1))
thread1.IsBackground = true
thread1.Start()
}
}
catch (ObjectDisposedException eee)
{
t = 2
goto ggg
}
catch (SocketException eeee)
{
t = 2
goto ggg
}
}
}
端口监听应该用改余橡的是UDP协议吧,获得源地址IP正常只能说明你已经可以和源地址通信,源端口号不是自己获得的,而是指定的,例:你自己的地址是192.168.0.2 端口:1001
源地址的地址是192.168.0.3 端口:5656
那么,你的Winsock1.Protocol = sckUDPProtocol设置未UDP协议
然后设置毁皮端口Winsock1.LocalPort = 1001
接着Winsock1.RemotePort = 5656
Winsock1.RemoteHost =“192.168.0.3”
绑定本地端口Winsock1.Bind “192.168.0.2”
这样就监听成功了,核旁程序我没有测试,你先按照自己的本地配置修改试试看
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)