|
Blue Forest http://www.lslnet.com at 10:18 on June 6, 2006
Socket Programming and Shared Memory I used to write a socket and a terminal services client. Write data to the end of a * Client service, the writing is irregular. These data services will be received wrote end of a shared memory.
I write a service dedicated terminal b of the sensed data from the shared memory, then there may be a lot of Client b link, as long as they have connecting service will end b data from the shared memory of the client b distribution.
The question now is :
Each client terminal b b connect to the service, how the service terminal b how socked accept the same generation. And two client services connected to the terminal b b, assuming a * client services for end to write two packets, each client only received one packet.
Members predecessors, please enlighten me! |
Socket Programming and Shared Memory This is certainly a question of your code. Ask people how do you answer? |
Socket Programming and Shared Memory That seems not quite understand. |
Socket Programming and Shared Memory If such a description is part of the standard software and do the things we must be very fun!
It appears that at present there is a problem of education, spent too much time learning English, leading to the description of the problem did not learn how to use Mandarin.
Make a joke, not really. |
Socket Programming and Shared Memory The plots have read quite a few times, or is it difficult to understand your description, no matter what used to test the select function |
Socket Programming and Shared Memory So hard to describe the feelings you so. : Oops :
For a way to try something :
There are two procedures : a wiretapping wiretapping frontal (only) sent the data be incorporated into shared memory;
Another monitor client connections, as long as they have the client has connected on shared memory sensed data sent from the client (s).
The question now is : If the data from the front-end system has been two and a client company, the two client data can be received; But even with the two clients, each client can get a data. |
Socket Programming and Shared Memory Oh, brothers and I share it. |
Socket Programming and Shared Memory Understand what you mean is, you do not have code stickers, and how to find the problem? This method can certainly be achieved, not you realize that your code is definitely a problem. |
Socket Programming and Shared Memory Mutex yet? |
Socket Programming and Shared Memory We put a code analysis Tieshanglai |
Socket Programming and Shared Memory Counter signal is the amount of time the problem. Thank you!
JohnBull withheld special thanks for the reminder! |
Socket Programming and Shared Memory Code can be sticky, and if we learn about. |
Socket Programming and Shared Memory [code]/* Create frontal daemon */
If (!fork ())
{
LEAVES OF 13 SPECIES OF LAURACEAE create socket*/
If ((SockFd=socket (AF_INET, SOCK_STREAM,0)) "0)
Printf ( "socket error.\n");
Opt=SO_REUSEPORT;
Setsockopt (SockFd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof (opt));
LEAVES OF 13 SPECIES OF LAURACEAE address allocation structure ServAddr*/
Bzero ((char *) &ServAddr, sizeof (ServAddr));
ServAddr.sin_family = AF_INET;
ServAddr.sin_addr.s_addr = htonl (INADDR_ANY);
ServAddr.sin_port = htons (SERV_TCP_PORT);
LEAVES OF 13 SPECIES OF LAURACEAE data transmission port address specified socket */
If (bind (SockFd, (struct sockaddr*) &ServAddr, sizeof (ServAddr)) "0)
{
Err_dump ( "Server:bind error. ");
Return 1;
}
LEAVES OF 13 SPECIES OF LAURACEAE establish a data input queue */
Listen and (SockFd,5);
While (1)
{
Client=sizeof (CliAddr);
NewSockFd=accept (SockFd, (struct sockaddr *) &CliAddr, &Client);
LEAVES OF 13 SPECIES OF LAURACEAE wait for the process of listening */ customers
If (NewSockFd>;=0)
{
If (!fork ())
{
Printf ( "connecting FRONT nessockfd:[%d]\n" NewSockFd);
PCliAddrStr=inet_ntoa (CliAddr.sin_addr);
LEAVES OF 13 SPECIES OF LAURACEAE address format change for the show */
CliPort=ntohs (CliAddr.sin_port);
Printf ( "connect from remote ip address:%s.\nremote port:%d.\n" \
PCliAddrStr, CliPort);
Close (SockFd);
LEAVES OF 13 SPECIES OF LAURACEAE time transmission of data into the frontal */
Memset (packet,0, sizeof (packet));
Printf ( "---------------------- be read \n");
N=read (NewSockFd, packet,1024);
If (n>;0)
{
Printf ( "---------------------- have read \n");
LEAVES OF 13 SPECIES OF LAURACEAE waiting for the signal to write shared memory */ 0:00 a.m.
If ((Sem=semop (SemId, &zero,1)) ==0)
{
Printf ( "---------------------- write shared memory \n");
Memset (pCommrReg->;MyMessage,0, sizeof (pCommrReg->;MyMessage));
Memcpy (pCommrReg->;MyMessage, packet, strlen (packet));
Printf ( "pCommrReg->;MyMessage:[%s]\n into shared memory," pCommrReg->;MyMessage);
}
}
If (n<=0)
{
If (n==0)
{
Err_dump ( "Client Aleady Closed!");
Close (NewSockFd);
Return 1;
}
If (n< 0)
{
Err_dump ( "read error");
Close (NewSockFd);
Return 1;
}
}
IGpid=getpgid (getppid ());
Killpg (iGpid, SIGUSR2);
Return 1;
}
Else
{
Close (NewSockFd); LEAVES OF 13 SPECIES OF LAURACEAE father closure process linking */
}
}
}
}
LEAVES OF 13 SPECIES OF LAURACEAE surveillance aircraft to guard the building process */
If (!fork ())
{
LEAVES OF 13 SPECIES OF LAURACEAE create socket*/
If ((nSockFd=socket (AF_INET, SOCK_STREAM,0)) "0)
Printf ( "socket error.\n");
Opt=SO_REUSEPORT;
Setsockopt (nSockFd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof (opt));
LEAVES OF 13 SPECIES OF LAURACEAE address allocation structure ServAddr*/
Bzero ((char *) &nServAddr, sizeof (nServAddr));
NServAddr.sin_family = AF_INET;
NServAddr.sin_addr.s_addr = htonl (INADDR_ANY);
NServAddr.sin_port = htons (SERV_TCP_PORT_MONITOR);
LEAVES OF 13 SPECIES OF LAURACEAE data transmission port address specified socket */
If (bind (nSockFd, (struct sockaddr*) &nServAddr, sizeof (nServAddr)) "0)
{
Err_dump ( "Server:bind error. ");
Return 1;
}
LEAVES OF 13 SPECIES OF LAURACEAE establish a data input queue */
Listen and (nSockFd,5);
While (1)
{
NClient=sizeof (nCliAddr);
NNewSockFd=accept (nSockFd, (struct sockaddr *) &nCliAddr, &nClient);
LEAVES OF 13 SPECIES OF LAURACEAE wait for the process of listening */ customers
If (nNewSockFd>;=0)
{
If (!fork ())
{
Printf ( "monitor linked nessockfd:[%d]\n" nNewSockFd);
PnCliAddrStr=inet_ntoa (nCliAddr.sin_addr);
LEAVES OF 13 SPECIES OF LAURACEAE address format change for the show */
NCliPort=ntohs (nCliAddr.sin_port);
Printf ( "connect from remote ip address:%s.\nremote port:%d.\n" \
PnCliAddrStr, nCliPort);
Close (nSockFd);
Signal (SIGUSR2, WriteClient);
Wait (sleep (3));
While (1)
{
Sleep (1);
Signal (SIGUSR2, WriteClient);
}
}
Else
{
Close (nNewSockFd); LEAVES OF 13 SPECIES OF LAURACEAE father closure process linking */
}
}
}
}
WriteClient which is a realization of the shared memory with the time counter function. Reading plus 1 minus 1 reading. [code][/code][/code] |
Socket Programming and Shared Memory How one meant, turned left alignment Later on, however : o |
Socket Programming and Shared Memory Use code functions in the course is closed on weekends and on United Nations holidays to find that in the editorial above mine |
Socket Programming and Shared Memory Thank you upstairs, D : |
| |