1 Example (UDP Client) // This program sends UDP packets to the given address #include #define SERVER_ADDR "127.0.0.1" #define SERVER_PORT 5555 void error(char.

Slides:



Advertisements
Similar presentations
Network Programming Topics Peeking at Internet traffic Programmer’s view of the Internet (review) Sockets interface Writing clients and servers Understanding.
Advertisements

Chris Riesbeck, Fall 2007 Network Programming Topics –Sockets interface –Writing clients and servers.
Socket Programming Application Programming Interface.
Elementary TCP Sockets Computer Networks Computer Networks Term B10 UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Sockets Basics Conectionless Protocol. Today IPC Sockets Basic functions Handed code Q & A.
תקשורת באינטרנט Tutorial 8. 2 n Socket programming u What is socket ? u Sockets architecture u Types of Sockets u The Socket system calls u Data Transfer.
Network Programming November 19, 2007 Topics Peeking at Internet traffic Programmer’s view of the Internet (review) Sockets interface Writing clients and.
TDC561 Network Programming Camelia Zlatea, PhD Week 2 – part II: Socket Application Programming Interface.
Network Programming Nov 21, 2002 Topics Programmer’s view of the Internet (review) Sockets interface Writing clients and servers class26.ppt “The.
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
Internetworking II: Network programming April 20, 2000 Topics client/server model Berkeley sockets –TCP client and server examples –UDP client and server.
Networking S04, Recitation, Section A
Recitation 12: 11/25/02 Outline Socket Interface –Echo Client/Server Http Protocol Evaluation Annie Luo Office Hours: Thursday.
Ashutosh Shukla Lecture 3 Network Programming CS 640: Computer Networking.
Elementary UDP Sockets© Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid Computer.
Socket programming in C. Socket programming Socket API introduced in BSD4.1 UNIX, 1981 explicitly created, used, released by apps client/server paradigm.
ECE 4110 – Internetwork Programming Client-Server Model.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Sirak Kaewjamnong Computer Network Systems
Lab #1: Network Programming using Sockets By J. H. Wang Nov. 28, 2011.
Recitation 12 (Nov. 29) Outline Socket programming Lab 7: part 1 Reminder Lab 7: Due next Thursday Minglong Shao Office hours: Thursdays.
Ports Port - A 16-bit number that identifies the application process that receives an incoming message. Reserved ports or well-known ports (0 to 1023)
Technical Details for sockaddr_in Structure Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Lab 5 Sockets. Useful Sockets Links (courtesy of Stanford University) Programming UNIX Sockets in C - Frequently Asked Questions
1 Socket Programming r What is a socket? r Using sockets m Types (Protocols) m Associated functions m Styles m We will look at using sockets in C.
Carnegie Mellon 1 Network Programming / : Introduction to Computer Systems 21 st Lecture, Nov. 7, 2013 Instructors: Randy Bryant, Dave O’Hallaron,
Cli/Serv.: sockets 3/91 Client/Server Distributed Systems v Objectives –describe iterative clients and servers using the UDP protocol ,
Network programming Nov 16, 2000 Topics Client-server model Sockets interface Echo client and server class24.ppt “The course that gives CMU its.
Carnegie Mellon Introduction to Computer Systems /18-243, spring th Lecture, Nov. 5 th Instructors: Roger Dannenberg and Greg Ganger.
CSCE 515: Computer Network Programming UDP Socket Wenyuan Xu Department of Computer Science and Engineering.
Elementary TCP Sockets UNIX Network Programming Vol. 1, Second Ed. Stevens Chapter 4.
Introduction to Socket
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Programming with UDP – II Covered Subjects: Creating UDP sockets Client Server Sending data Receiving data Connected mode.
Socket Program Training 10/29/ TCP Client Socket ( ) Connect ( ) send ( ) Close ( ) send ( ) Read ( ) Accept ( ) recv ( ) Listen ( ) Bind ( ) Socket.
S OCKET P ROGRAMMING IN C Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Read() recv() connection establishment Server (connection-oriented protocol) blocks until connection from client Client socket() bind() listen() accept()
2: Application Layer 1 Socket Programming UNIX Network Programming, Socket Programming Tutorial:
CSCI 330 UNIX and Network Programming Unit XIV: User Datagram Protocol.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
The Socket Interface A Networking Application Program Interface.
1 Networking Programming. 2 Outline Connection & Socket Sockets Interface –Functions –Echo Client and Server Suggested Reading: –11.4.
CS 447 Networks and Data Communication Server-Process Organization IP address and SockAddr_In Data Structure Department of Computer Science Southern Illinois.
Socket programming in C. Socket programming with TCP Client must contact server server process must first be running server must have created socket (door)
Lecture 3 TCP and UDP Sockets CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming Jignesh Patel Palanivel Rathinam connecting processes.
1 Socket Interface. 2 Basic Sockets API Review Socket Library TCPUDP IP EthernetPPP ARP DHCP, Mail, WWW, TELNET, FTP... Network cardCom Layer 4 / Transport.
Sockets and Beginning Network Programming
Socket programming in C
CS 1652 Jack Lange University of Pittsburgh
Elementary UDP Sockets
Extending echo server HTTP Broken pipe error Feedback and evaluation
Instructors: Anthony Rowe, Seth Goldstein and Greg Kesden
Network Programming /18-243: Introduction to Computer Systems
Network Programming April 11, 2008
CHAPTER 8 ELEMENTARY UDP SOCKETS
Network programming Nov 27, 2001
Recitation 11 – 4/29/01 Outline Sockets Interface
UDP Sockets Programming
Networking Programming
Chapter 06. UDP Server/Client.
Yu-Chi Lai Lecture 3 Network Programming
Network Programming November 3, 2008
Chapter 04. TCP Server/Client.
Example (UDP Client) // This program sends UDP packets to the given address #include #include #include #include.
Internet Networking recitation #8
Socket programming in C
Presentation transcript:

1 Example (UDP Client) // This program sends UDP packets to the given address #include #define SERVER_ADDR " " #define SERVER_PORT 5555 void error(char *str) { printf("\n%s", str); exit(0); } int main(int argc, char *argv[]) { char message[100], message2[10]; int sockfd, res; struct sockaddr_in client_addr, server_addr; int i, mesNum; printf("\nClient is running..."); if (argc < 2) error("\nYou should supply parameter: the number of messages to send");

2 Example (UDP Client) // Opening socket if ((sockfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) error("Could not open socket"); // Sending a message to the server bzero((char*) &server_addr, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = inet_addr(SERVER_ADDR); server_addr.sin_port = htons(SERVER_PORT); mesNum = atoi(argv[1]); if (mesNum == 0) error("\nIllegal parameter"); for (i=0; i<mesNum; i++) { strcpy(message, "Test message: "); sprintf(message2, "%d", i+mesNum); strcat(message, message2); res = sendto (sockfd, message, strlen(message)+1, 0, (struct sockaddr*)&server_addr, sizeof(server_addr)); printf("\nClient sent %d bytes", res); }

3 Example (UDP Server) // This program receives UDP packets #include #define SERVER_PORT 5555 #define MAX_MESSAGE_SIZE 100 void error(char *str) { printf("\n%s", str); exit(0); } int main() { char message[MAX_MESSAGE_SIZE]; int sockfd, res; struct sockaddr_in client_addr, server_addr; int addr_len; printf("\nServer is running..."); fflush(stdout);

4 Example (UDP Server) // Opening socket if ((sockfd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) error("Could not open socket"); // Bind local ip and process addresses bzero((char*) &server_addr, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(SERVER_PORT); if ( bind (sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) < 0) error("Could not bind to the socket"); while (1) { // Receiving a message from the client addr_len = sizeof(client_addr); res = recvfrom (sockfd, message, MAX_MESSAGE_SIZE, 0, (struct sockaddr*)&client_addr, &addr_len); printf("\nServer received %d bytes", res); printf("\n%s", message); fflush(stdout); }