Reputation: 53
I wrote a program in C# that sends SMS using GSM LAN Modem(Coniugo). I'm using socket as client to asynchronously connect to the GSM LAN Modem. The Modem IP address is 192.186.2.1, and the port is 10001. I use this code to start the connection to the 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();
}
}
When i run the code and start to connect to the Modem from a host in the network, the connection works without problem, but when i try run the code on another host, the connection does not work. I got the exception message
No connection could be made because the target machine actively refused it 192.186.2.1:10001.
How to connect to the GSM Modem from several hosts using socket, and avoid this exception?
Upvotes: 1
Views: 876
Reputation: 357
You cannot. The network adapter (from Lantronix) in the Coniugo GSM modem will only accept one connection at a time.
This is necessary: The modem itself cannot deal with multiple connections. The modem actually uses serial communications - that can only handle one connection. If you allow multiple TCP connections, two users could send data at the same time. The modem cannot deal with that situation.
You have two options:
Your program only connects to the modem for as long as it takes to send the SMS. Enter all your data, hit send, and the program connects, sends the SMS, then disconnects.
You write a server program that connects to the modem. Your clients who want to send an SMS connect to the service, and it handles queueing and sending the SMS as well a keeping indiviual clients informed of the state.
I'd go for option 2.
Upvotes: 0