【发布时间】:2017-07-29 06:37:03
【问题描述】:
我用 C# 编写了一个使用 GSM LAN 调制解调器(Coniugo)发送 SMS 的程序。我使用套接字作为客户端异步连接到 GSM LAN 调制解调器。 Modem IP 地址为 192.186.2.1,端口为 10001。我使用此代码启动与 Modem 的连接
AsynchronousClient smsClient; // the clinet manager
IPAddress ipAddress;
int port;
IPEndPoint remoteEP;
// Create a TCP/IP socket.
Socket client;
private void btnStartConnect_Click(object sender, EventArgs e)
{
try
{
ipAddress = IPAddress.Parse("192.186.2.1");
port = 10001;
remoteEP = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
// Connect to the remote endpoint.
client.BeginConnect(remoteEP,
new AsyncCallback(smsClient.ConnectCallback), client);
smsClient.connectDone.WaitOne();
if (client.Connected)
{
lblStatus.Text = "Client is Connected";
smsClient.Receive(client);
}
else
{
lblStatus.Text = "Client is Not Connected";
}
}
catch (Exception ex)
{
lblStatus.Text = ex.ToString();
}
}
当我运行代码并开始从网络中的主机连接到调制解调器时,连接没有问题,但是当我尝试在另一台主机上运行代码时,连接不起作用。我收到异常消息
No connection could be made because the target machine actively refused it 192.186.2.1:10001.
如何使用socket从多个主机连接到GSM Modem,并避免这个异常?
【问题讨论】:
标签: c# sockets network-programming client-server sms-gateway