用VSPM软件模拟串口通讯,VSPM设置在client模式,请问服务器端该怎么建立才能接收到有VSPM发出的信息?
namespaceSocketServer{publicpartialclassForm1:Form{publicForm1(){InitializeComponent(...
namespace SocketServer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
com.Open();
}
private Socket s;
// private Thread th;
public Socket cSocket;
SerialPort com = new SerialPort("COM5");
public void Communication()
{
while (true)
{
try
{
cSocket = s.Accept();
string str = com.ReadExisting();
lbInfo.Items.Add(str);
}
catch (SocketException ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
try
{
s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress serverIP = IPAddress.Parse("115.156.252.8");
IPEndPoint server = new IPEndPoint(serverIP, 6027);
s.Bind(server);
s.Listen(1);
Thread th = new Thread(new ThreadStart(Communication));
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这是我写的代码,VSPM显示tcp/ip连接已建立,点重新连接,就一直显示Connection refused
跪问各位大虾 是哪里出了问题哈?
防火墙关了也没用啊,把VSPM设在server模式可以正常通信,设在client就不知道为什么搞不定了,求指教啊。。。
等级太低,想发两张图都发不了。。。 展开
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
com.Open();
}
private Socket s;
// private Thread th;
public Socket cSocket;
SerialPort com = new SerialPort("COM5");
public void Communication()
{
while (true)
{
try
{
cSocket = s.Accept();
string str = com.ReadExisting();
lbInfo.Items.Add(str);
}
catch (SocketException ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
try
{
s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress serverIP = IPAddress.Parse("115.156.252.8");
IPEndPoint server = new IPEndPoint(serverIP, 6027);
s.Bind(server);
s.Listen(1);
Thread th = new Thread(new ThreadStart(Communication));
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这是我写的代码,VSPM显示tcp/ip连接已建立,点重新连接,就一直显示Connection refused
跪问各位大虾 是哪里出了问题哈?
防火墙关了也没用啊,把VSPM设在server模式可以正常通信,设在client就不知道为什么搞不定了,求指教啊。。。
等级太低,想发两张图都发不了。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询