Sponsored Content
Homework and Emergencies Homework & Coursework Questions Client/server atm with sockets Post 302371307 by tamanas on Saturday 14th of November 2009 05:56:03 AM
Old 11-14-2009
Client/server atm with sockets

Hello everyone!I would appreciate any help you could give me,I have to make a program of an atm machine using client server sockets and semaphores.I know how to construct an ATM in c++ but don't know anything about unix c.The problem is that Don't know what to do and how to link the two programs together.







3.

Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
void error(char *);

void main(int argc, char *argv[])
{
   int sockfd, servlen,n;
   struct sockaddr_un  serv_addr;
   char buffer[82];

   bzero((char *)&serv_addr,sizeof(serv_addr));
   serv_addr.sun_family = AF_UNIX;
   strcpy(serv_addr.sun_path, argv[1]);
   servlen = strlen(serv_addr.sun_path) + 
                 sizeof(serv_addr.sun_family);
   if ((sockfd = socket(AF_UNIX, SOCK_STREAM,0)) < 0)
       error("Creating socket");
   if (connect(sockfd, (struct sockaddr *) 
                         &serv_addr, servlen) < 0)
       error("Connecting");
   printf("Please enter your message: ");
   bzero(buffer,82);
   fgets(buffer,80,stdin);
   write(sockfd,buffer,strlen(buffer));
   n=read(sockfd,buffer,80);
   printf("The return message was\n");
   write(1,buffer,n);   
}

void error(char *msg)
{
    perror(msg);
    exit(0);
}

/* a server in the unix domain.  The pathname of 
   the socket address is passed as an argument */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
void error(char *);
int main(int argc, char *argv[])
{
   int sockfd, newsockfd, servlen, clilen, n;
   struct sockaddr_un  cli_addr, serv_addr;
   char buf[80];

   if ((sockfd = socket(AF_UNIX,SOCK_STREAM,0)) < 0)
       error("creating socket");
   bzero((char *) &serv_addr, sizeof(serv_addr));
   serv_addr.sun_family = AF_UNIX;
   strcpy(serv_addr.sun_path, argv[1]);
   servlen=strlen(serv_addr.sun_path) + 
                     sizeof(serv_addr.sun_family);
   if(bind(sockfd,(struct sockaddr *)&serv_addr,servlen)<0)
       error("binding socket"); 

   listen(sockfd,5);
   clilen = sizeof(cli_addr);
   newsockfd = accept(
        sockfd,(struct sockaddr *)&cli_addr,&clilen);
   if (newsockfd < 0) 
        error("accepting");
   n=read(newsockfd,buf,80);
   printf("A connection has been established\n");
   write(1,buf,n);
   write(newsockfd,"I got your message\n",19);
}

void error(char *msg)
{
    perror(msg);
    exit(0);
}
:



4. Computer engineering informatics Department (University), Patras , Greece, Triantafylou, 330(operating systems):


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by bakunin; 11-15-2009 at 10:08 PM.. Reason: added code-tags. Please provide them yourself henceforth
 

10 More Discussions You Might Find Interesting

1. Programming

Sockets donot send any thing to client

I have written a socket program in C under RedHat Linux 6.2. This program is using SOCK_STREAM (TCP) to connect to any ip address at port # 23. The program is hosted on the linux machine and works well with Cisco routers. But when I am trying to connect to the same linux machine, it does not return... (4 Replies)
Discussion started by: biswa
4 Replies

2. UNIX for Advanced & Expert Users

FTP over ATM issue

We just recently upgraded our T1 wan link to a 10Mbit ATM link. Windows pc's seem fine and get great speed, however we have 2 Sco unix box's that seem really slow at FTPing now. both Sco box's are SCO OpenServer Enterprise System (ver 5.0.5m) compaq ML530's I'm not really sure what to... (4 Replies)
Discussion started by: whegra
4 Replies

3. UNIX for Dummies Questions & Answers

client/server

Hi, yes i belong to that duummies group of people so here is the question that i need someone to explain it to me and posiblly to answere it to me in a plain english. This is the question: Describe the concept of “client-server” software. Discuss what each side of the equation... (2 Replies)
Discussion started by: bole
2 Replies

4. Programming

How to acknowledge from client to server in sockets

Hi all, i am having a doubt regarding how to get the acknowledgement(reply) from client to server & how to recieve at the server....imagine there r 8 frames...we have to send first 4frames at a time and after tat we have to receive and ack and only after receiving an ack we have to send... (1 Reply)
Discussion started by: Rohil
1 Replies

5. Shell Programming and Scripting

Client-server

Hi, I have installed the vmware server on my debian os and has several clients connected to it. Is there any script that enable the server to restart the client automatically?? Can anyone help. Thanks in advance (3 Replies)
Discussion started by: kanexxx
3 Replies

6. Programming

Client/Server Socket Application - Preventing Client from quitting on server crash

Problem - Linux Client/Server Socket Application: Preventing Client from quitting on server crash Hi, I am writing a Linux socket Server and Client using TCP protocol on Ubuntu 9.04 x64. I am having problem trying to implement a scenario where the client should keep running even when the... (2 Replies)
Discussion started by: varun.nagpaal
2 Replies

7. Windows & DOS: Issues & Discussions

Office server => laptop =>client server ...a lengthy and laborious ftp procedure

Hi All, I need your expertise in finding a way to solve my problem.Please excuse if this is not the right forum to ask this question and guide me to the correct forum,if possible. I am a DBA and on a daily basis i have to ftp huge dump files from my company server to my laptop and then... (3 Replies)
Discussion started by: kunwar
3 Replies

8. Programming

Client Server C

Hello, Please I would create a client and a server in C that communicate frequently. The client sends "hello message" to the server, the server waits a few minutes and sends a "hello message" to the client, the client sends again "hello server ".. etc up to 15 minutes Can you guide me... (3 Replies)
Discussion started by: chercheur857
3 Replies

9. UNIX for Dummies Questions & Answers

Client server C

Hello, Please, is there on unix.com the source code of a client C and server C: as shown in following figure: File:InternetSocketBasicDiagram zhtw.png - Wikipedia, the free encyclopedia Thank you so much for help (1 Reply)
Discussion started by: chercheur857
1 Replies

10. Shell Programming and Scripting

Sftp script for dev server to client server

hi, i am new to unix, cuold u send some sftp acripts to send files to dev server to clint server, (1 Reply)
Discussion started by: Koti.annam
1 Replies
FATM(4) 						   BSD Kernel Interfaces Manual 						   FATM(4)

NAME
fatm -- device driver for Fore PCA200E ATM interfaces SYNOPSIS
device fatm device utopia device atm options NATM DESCRIPTION
The fatm device driver supports the FORE (now Marconi) PCA200E ATM interface cards. The driver interfaces with the natm(4) framework, netgraph(4) and HARP. It provides only PVC services. Signalling, ATMARP, ILMI and other higher layer protocols are implemented using netgraph(4) or HARP. For configuring the card for IP see natmip(4). The following sysctls are recognized by the driver additionally to those handled by utopia(4): hw.atm.fatmN.stats Returns a device specific statistic list of uint32_t statistic counters. hw.atm.fatmN.istats Returns a list of uint32_t with internal driver statistics. hw.atm.fatmN.retry_tx If this is set packets are stuffed back into the interface's send queue when the cards transmit queue is found to be full. They are transmitted later. If this is not set the packets are dropped. It may be useful to set this if only UBR traffic is sent. hw.atm.fatmN.debug (Only if debugging enabled.) These are debugging flags. See src/sys/dev/fatm/if_fatmvar.h for the possible flags. The driver supports the media options sdh, noscramb and unassigned (see utopia(4)). DIAGNOSTICS
fatm0: <FORE PCA200E> mem 0xd5800000-0xd59fffff irq 9 at device 9.0 on pci0 SEE ALSO
natm(4), natmip(4), utopia(4) AUTHORS
Harti Brandt <harti@FreeBSD.org> BUGS
These cards can CBR shape a single VCC only. It is currently possible to request more than one CBR connection. In this case all the timing will be wrong. See hatm(4) for a better card. BSD
May 15, 2003 BSD
All times are GMT -4. The time now is 06:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy