客户端的SoftEther连接不上!!!请教各位SoftEther高手!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了客户端的SoftEther连接不上!!!请教各位SoftEther高手!相关的知识,希望对你有一定的参考价值。
参考技术A 我认为是防火墙的问题要在防火墙上打开如下端口
7777(此为默认端口,需根据你的设置更改),443,8023(管理端口,可不开)
softether的使用方法可以查看以下地址
http://zhidao.baidu.com/question/34011917.html?si=2
或
http://tech.163.com/05/0512/09/1JHU94H000091589_3.html
Socket服务器端如何检测客户端的连接状态?
Socket TCP/IP通信中,服务器端如何检测到客户端的断开连接动作,由于客户端不是我编写的,所以不能要求客户端在断开连接时发送断开消息,我的服务器端也不能通过定时向客户端发送指令检测客户端的连接状态,会造成客户端接收数据的混乱
请问各位大虾,服务器端有没有其他办法能够检测到客户端断开连接的动作?
环境是C#.NET
客户端与服务端都不发送心跳包
可以的话给个实例啊,谢谢了
首先谢谢wefgod3,但是你给我的不是我想要的
我的服务端开启了多线程,每个客户端连接一个线程,当客户端执行Socket.Shutdown、Socket.Close()主动断开连接时,希望服务端能够检测到客户端的这个动作,然后取消与此客户端相连的线程和Socket
现在我不知道是服务端上层在不主动发送心跳包的情况下,如何得知客户端的Socket已经关闭了
http://msdn.microsoft.com/zh-cn/library/system.net.sockets.aspx
这里例子很多
但是具体的可能你看比我看好···毕竟你比我了解的多
里面的类可能你能用到
既然这样我还是直接给你两个看看算了···
TcpListener 类
从 TCP 网络客户端侦听连接。
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
class MyTcpListener
public static void Main()
TcpListener server=null;
try
// Set the TcpListener on port 13000.
Int32 port = 13000;
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
// TcpListener server = new TcpListener(port);
server = new TcpListener(localAddr, port);
// Start listening for client requests.
server.Start();
// Buffer for reading data
Byte[] bytes = new Byte[256];
String data = null;
// Enter the listening loop.
while(true)
Console.Write("Waiting for a connection... ");
// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient client = server.AcceptTcpClient();
Console.WriteLine("Connected!");
data = null;
// Get a stream object for reading and writing
NetworkStream stream = client.GetStream();
int i;
// Loop to receive all the data sent by the client.
while((i = stream.Read(bytes, 0, bytes.Length))!=0)
// Translate data bytes to a ASCII string.
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
Console.WriteLine("Received: 0", data);
// Process the data sent by the client.
data = data.ToUpper();
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
// Send back a response.
stream.Write(msg, 0, msg.Length);
Console.WriteLine("Sent: 0", data);
// Shutdown and end connection
client.Close();
catch(SocketException e)
Console.WriteLine("SocketException: 0", e);
finally
// Stop listening for new clients.
server.Stop();
Console.WriteLine("\nHit enter to continue...");
Console.Read();
TcpClient 类
为 TCP 网络服务提供客户端连接。
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();
本回答被提问者采纳
以上是关于客户端的SoftEther连接不上!!!请教各位SoftEther高手!的主要内容,如果未能解决你的问题,请参考以下文章