Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP WITH SOCKETS

hey guys i have the code for the client and server.
I just want to connect 3 servers to one client for handoff implementation.
I am newbie and not able to figure it out. can any one help me.
i am posting the code below.

client

#include
#include
#include
#include
#include
#include
#include

#define SOCK_PATH "echo_socket"

int main(void)
{
int s, t, len;
struct sockaddr_un remote;
char str[100];

if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}

printf("Trying to connect...
");

remote.sun_family = AF_UNIX;
strcpy(remote.sun_path, SOCK_PATH);
len = strlen(remote.sun_path) + sizeof(remote.sun_family);
if (connect(s, (struct sockaddr *)&remote, len) == -1) {
perror("connect");
exit(1);
}

printf("Connected.
");

while(printf("> "), fgets(str, 100, stdin), !feof(stdin)) {
if (send(s, str, strlen(str), 0) == -1) {
perror("send");
exit(1);
}

if ((t=recv(s, str, 100, 0)) > 0) {
str[t] = '';
printf("echo> %s", str);
} else {
if (t < 0) perror("recv");
else printf("Server closed connection
");
exit(1);
}
}

close(s);

return 0;
}



server:

#include
#include
#include
#include
#include
#include
#include

#define SOCK_PATH "echo_socket"

int main(void)
{
int s, s2, t, len;
struct sockaddr_un local, remote;
char str[100];

if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(1);
}

local.sun_family = AF_UNIX;
strcpy(local.sun_path, SOCK_PATH);
unlink(local.sun_path);
len = strlen(local.sun_path) + sizeof(local.sun_family);
if (bind(s, (struct sockaddr *)&local, len) == -1) {
perror("bind");
exit(1);
}

if (listen(s, 5) == -1) {
perror("listen");
exit(1);
}

for(i=0;i<2;i++) {
int done, n;
printf("Waiting for a connection...
");
t = sizeof(remote);
if ((s2 = accept(s, (struct sockaddr *)&remote, &t)) == -1) {
perror("accept");
exit(1);
}

printf("Connected.
");

done = 0;
do {
n = recv(s2, str, 100, 0);
if (n <= 0) {
if (n < 0) perror("recv");
done = 1;
}

if (!done)
if (send(s2, str, n, 0) < 0) {
perror("send");
done = 1;
}
} while (!done);

close(s2);
}

return 0;
}


please tell me how to connect 3 servers wwith one client..
here is the explanation of problem
ms1-client
bts1-server
bts2-server
msc-server

now what i have to do is implement handoff
first ms1 is connected to bts1 when the signal strenght from bts1 is lower then bts2 the handoff is implemented and ms1 get connected to bts2 and the current bts informs the msc that its the current bts.
please help me with this this is my project.. have to submit it by wed...

Comments

Sign In or Register to comment.