The 2nd arduino as telnet clients does not connect to ubuntu socket serve

Hi,

I am run into a issue and i could not figure out why.

I set up a socket server on my desktop running Ubuntu and then i use ethernet->telnetClient example to create a socket client running on arduino-uno. I am using three arduino running the same software, but each arduino will keep sending different heart beat message to socket server, so that server knows which one is which.

If am running one arduino, it works perfectly...But if i start the 2nd one while the 1st one is running, both of the two arduino start disconnecting and connecting...(the firmware will check the connection status, if the connection lost, it will try to reconnect to the server). and the server will crash...

I really confused, why one arduino is working, two is not working. From the server side, i have tried to use multithreading to cope with the each connected arduino clients, does not work as expected.

For the same server, i create a same socket client running on my Unubtu machine, it works perfectly.

I also tried to create a two server, with the same IP address but different port, and let the two arduino connect to different port with different server---baiscally, two main function. when the 2nd one trying to connect, the server also failed.

Totally lost...

Please give me some idea on this and i will be very grateful.

Li

Please...

First, bumping your Post after less than 48 hours is very unreasonable.

Second. Post your program.

Third, it sounds to me like this is a server problem rather than an Arduino problem.

...R

Thanks for your reply and i really appreciate that. Here is my server program.
I have tried to start three clients on my Ubuntu desktop to simulate three arduinos, they works perfectly. However, the same server, i start one arduino it is okay, when i started the 2nd arduino both of the two arduino connecting and disconnecting, the arduino running telnetClient example program, and i added reconnect operation when disconnection was detected from arduino side.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void client_handler(int client_sockfd)
{
char recv_buf[10];
char send_buf[10] = "ping";

/* We can now read/write to client on client_sockfd. */
while(1)
{
static int cnts = 0;
cnts++;
printf("server is connected with client_sockfd = %d ---------- %d\n", client_sockfd, cnts);

char cmd;
memset(recv_buf, 0, sizeof(char));

write(client_sockfd, &send_buf, 10);
printf("server-send msg: %s\n", send_buf);
read(client_sockfd, &recv_buf, 10);
printf("server-rcvd msg: %s\n", recv_buf);

sleep(1);
}
close(client_sockfd);
}

int main()
{
int server_sockfd, client_sockfd;
socklen_t server_len, client_len;
struct sockaddr_in server_address;
struct sockaddr_in client_address;

/* Remove any old socket and create an unnamed socket for the server. */
server_sockfd = socket(AF_INET, SOCK_STREAM, 0);

/* Name the socket. */
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = inet_addr("192.168.1.141");
server_address.sin_port = htons(10002);
server_len = sizeof(server_address);
bind(server_sockfd, (struct sockaddr *)&server_address, server_len);

/* Create a connection queue and wait for clients. */
listen(server_sockfd, 5);

while(1)
{
printf("socket server waiting for connection request from socket clients...\n");

/* Accept a connection. */

client_len = sizeof(client_address);
client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);

cout << "new client with client_sockfd " << client_sockfd << " is connected." << endl;

std::thread th(client_handler, client_sockfd);
th.detach();
}

return 0;
}

lixueyi83:
Thanks for your reply and i really appreciate that. Here is my server program.

That looks like a PC program and this is a Forum for help with Arduino programs.

I don't know enough to comment on a PC server program written in C. I think if it was my problem I would try to get other PC clients working with it and take advantage of all the internet support for that sort of thing. Then when I know how to do it with PC clients I should be able to transfer that knowledge to an Arduino client.

...R

Each Uno Ethernet must have a different MAC address. Examples use funny MAC addresses like DEADBEEFFEED shown below. Just make sure each MAC address is different. If the Ethernet shields came with with MAC address stickers, use the addresses from the stickers.

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

If this does not work, fire up WireShark and capture what happens during a failure.

Thanks a lot for your reply amd i think you made the point on the MAC address. Frankly, i did use the same MAC for two arduinos.

I will try to use a different mac for different arduinos. Thanks a lot.