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
NG_ATMLLC(4)						   BSD Kernel Interfaces Manual 					      NG_ATMLLC(4)

NAME
ng_atmllc -- ATM LLC netgraph node type SYNOPSIS
#include <netgraph/ng_atmllc.h> DESCRIPTION
The atmllc node type translates frames in to and out of ATM LLC encapsulation, as specified by RFC 1483. In LLC encapsulation the protocol of a given protocol data unit (PDU) is specified by an IEEE 802.2 LLC header, possibly followed by an IEEE 802.1a SubNetwork Attachment Point (SNAP) header. This node currently handles the Ethernet and FDDI protocols. The node transmits and receives ATM PDUs on the atm hook. Received PDUs are decoded and forwarded to the ether or fddi hooks as appropriate. Data received on the ether or fddi hooks are assumed to be full Ethernet or FDDI packets as appropriate and are encapsulated into a PDU and transmitted via the atm hook. HOOKS
This node type supports the following hooks: atm ATM connection. Typically, this hook would be connected to a ng_atm(4) node, which handles transmission of ATM PDUs over an ATM device. ether Ethernet connection. This hook sends and receives Ethernet frames. This would normally be connected to an ng_eiface(4) node if in use. fddi FDDI connection. This hook sends and receives FDDI frames. CONTROL MESSAGES
This node type supports the generic control messages. SHUTDOWN
This node shuts down upon receipt of a NGM_SHUTDOWN control message, or when all hooks have been disconnected. SEE ALSO
netgraph(4), ng_atm(4), ng_eiface(4), ngctl(8) J. Heinanen, Multiprotocol Encapsulation over ATM Adaptation Layer 5, RFC 1483. AUTHORS
Benno Rice <benno@FreeBSD.org> BSD
March 8, 2004 BSD
All times are GMT -4. The time now is 07:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy