Onward with Chat! Networking CS 3470, Section 1.

Slides:



Advertisements
Similar presentations
Socket Programming 101 Vivek Ramachandran.
Advertisements

Computer Net Lab/Praktikum Datenverarbeitung 2 1 Overview Sockets Sockets in C Sockets in Delphi.
Sockets: Network IPC Internet Socket UNIX Domain Socket.
Taekyung Kim 0x410 ~ 0x International Standards Organization (ISO) is a multinational body dedicated to worldwide agreement on international.
Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
Today’s topic: Basic TCP API –Socket –Bind –Listen –Connect –Accept –Read –Write –Close.
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.
EECS122 Communications Networks Socket Programming January 30th, 2003 Jörn Altmann.
1 Pertemuan 10 Non Blocking Matakuliah: H0483 / Network Programming Tahun: 2005 Versi: 1.0.
Sockets Programming Introduction © Dr. Ayman Abdel-Hamid, CS4254 Spring CS4254 Computer Network Architecture and Programming Dr. Ayman A. Abdel-Hamid.
Tutorial 8 Socket Programming
CS 311 – Lecture 19 Outline Internet Sockets – gethostname utility – struct hostent – inet_addr – Machine byte to Network byte order translation and vice.
#include DatatypeDescription int8_t uint8_t int16_t uint16_t int32_t uint32_t Signed 8-bit integer Unsigned 8-bit integer Signed 16-bit integer Unsigned.
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)
Unix Network Programming Part 2: Elementary Sockets Jani Peusaari.
Sockets COS 518: Advanced Computer Systems Michael Freedman Fall
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
Agenda Internet Address Pair Internet Address Pair IP Address IP Address Port Address Port Address Network Address Translation (NAT) Network Address Translation.
Basic Socket Programming TCP/IP overview. TCP interface Reference: –UNIX Network Programming, by Richard Stevens. –UNIX man page.
ECE453 – Introduction to Computer Networks Lecture 15 – Transport Layer (II)
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Assignment 3 A Client/Server Application: Chatroom.
CS345 Operating Systems Φροντιστήριο Άσκησης 2. Inter-process communication Exchange data among processes Methods –Signal –Pipe –Sockets.
Sockets CIS 370 Lab 10 UMass Dartmouth. Introduction 4 Sockets provide a simple programming interface which is consistent for processes on the same machine.
Sirak Kaewjamnong Computer Network Systems
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Technical Details for sockaddr_in Structure Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lec 2 Rishi Kant. Review of Socket programming Decide which type of socket – stream or datagram. Based on type create socket using.
Networking Tutorial Special Interest Group for Software Engineering Luke Rajlich.
Introduction to Socket
Socket Programming Tutorial Department of Computer Science Southern Illinois University Edwardsville Fall, 2015 Dr. Hiroshi Fujinoki
Socket Programming Lab 1 1CS Computer Networks.
1 Sockets Programming Socket to me!. 2 Network Application Programming Interface (API) The services provided by the operating system that provide the.
Sockets Socket = abstraction of the port concept: –Application programs request that the operating system create a socket when one is needed –O.S. returns.
Intro to Socket Programming CS 360. Page 2 CS 360, WSU Vancouver Two views: Server vs. Client Servers LISTEN for a connection and respond when one is.
Sockets Introduction Socket address structures Value-result arguments
Introduction to Sockets
1 Network Programming. 2 Background Important guidelines –Use conductor.tamucc.edu or any LINUX machine to develop your network applications –Do not use.
1 Spring Semester 2008, Dept. of Computer Science, Technion Internet Networking recitation #7 Socket Programming.
Advanced UNIX programming Fall 2002 Instructor: Ashok Srinivasan Lecture 17 Acknowledgements: The syllabus and power point presentations are modified versions.
Lecture 15 Socket Programming CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
Socket Programming in C CS587x Lecture 3 Department of Computer Science Iowa State University.
Socket Programming(1/2). Outline  1. Introduction to Network Programming  2. Network Architecture – Client/Server Model  3. TCP Socket Programming.
LINKED LISTS.
Chapter 3 outline 3.1 Transport-layer services
Sockets and Beginning Network Programming
Network Programming CSC- 341
Socket Programming (Cont.)
CS 105 “Tour of the Black Holes of Computing”
Network Programming CSC- 341
CH5 TCP Client - Server Example:
Tutorial on Socket Programming
CS 1652 Jack Lange University of Pittsburgh
Name and Address Conversions Part I
Transport layer API: Socket Programming
Chapter 3 Sockets Introduction
UNIX Sockets Outline Homework #1 posted by end of day
Process-to-Process Delivery:
Lecture 2 Socket Programming
TRANSMISSION CONTROL PROTOCOL
Socket Programming(1/2)
Sockets Programming Socket to me!.
Sockets Programming Socket to me!.
Internet Networking recitation #8
Outline Communications in Distributed Systems Socket Programming
Today’s topic: Basic TCP API
TCP/IP Sockets in Java: Practical Guide for Programmers
Transport Layer 9/22/2019.
Transport Layer Our goals:
Presentation transcript:

Onward with Chat! Networking CS 3470, Section 1

Chat v1 Handing back grading sheets Average score = A- Common issues Makefile Argument checking Hardcoded port number Even though taking it in as a parameter!

Makefile # This is a comment. Don’t use C-style comments CC=gcc CFLAGS=-Wall all: chat chat: chat.c $(CC) -o chat chat.c $(CFLAGS) clean: rm chat

Argument Checking Part #1 int main(int argc, char **argv) { /* Are we invoking the server or client? Let's figure it out based * on the number of arguments. */ if(argc > 1) client(argc, argv); else server(); return 0;

Argument Checking Part #2 int client(int argc, char **argv) { struct hostent *hp; … /* Checking parameters */ /* There had better be exactly 5, else we are outa here. */ if (argc!=5) { print_usage(); exit(1); }

Argument Checking Part #3 /* There should be a flag in the first and third positions. */ if(strcmp(argv[1], "-p")==0) { port=atoi(argv[2]); host=argv[4]; } else if(strcmp(argv[3], "-p")==0) { port=atoi(argv[4]); host=argv[2]; else { /* Something is off */ print_usage(); exit(1);

Helpful Functions atoi – converts a string to an int strcmp or strncmp – compares two strings

Any other questions?

Onward Next program: full chat! Back and forth chatting Pretty formatting like on the original project specification Packet formatting Version header Src IP header Dst IP header Checksum field Length of message (always 140) Bad chat For testing!

Back and Forth Chatting Do this first! Both send() and rcv() must be in the client and server function’s while loops

Packet Formatting Your packet should look like this (Field sizes coming soon) Version Src IP Dest IP Data Checksum

Packet Formatting Version = 2 Src IP = IP of sender Dest IP = IP of receiver Data = chat message, always 140 bytes/characters long Checksum Version Src IP Dest IP Data Checksum

Packet Formatting How do I do this? Create a struct packet that holds all those fields Send the struct packet over the socket

Creating a Struct Packet Assign 2 to version field Get source and destination IP from socket, assign to src and dest fields Get user-typed chat message from fgets(), use strcpy (“string copy”) to copy it into data field Use checksum function on page 95 of your book to compute checksum of all previous fields

Checksum Sender creates checksum, copies it to end of packet, and sends packet through socket Receiver receives packet, creates checksum, and checks to see that computed checksum matches checksum found in packet If matches, it shouldn’t do anything If it doesn’t match, it should display an error to the user.

Bad Chat How can we test our checksum routines? We can invoke a bad checksum routine on chat by using a “–b” flag with either the client or the server This will invoke a second “bad checksum” function that appends an incorrect checksum to our packet Computing checksum on receiver side should always use “good” checksum function

Other Things Cannot have any pointers in struct packet before sending it over the socket Why?

Other Things Must be aware of byte ordering!

Byte Ordering High-order byte Low-order byte MSB 16-bit value LSB Increasing memory address Address A+1 Address A Little-endian byte order High-order byte Low-order byte MSB 16-bit value LSB Consider a 16-bit integer that is made up of 2 bytes: there are two ways to store the 2 bytes in memory, with low order byte at the starting address, known as little endian byte order, or with the high order byte at the starting address, known as big endian byte order Big-endian byte order Low-order byte High-order byte Address A+1 Address A Increasing memory address

Implications of Byte Order Unfortunately there is no standard between these two byte orderings and we encounter systems that use both formats We refer to the byte ordering used by a given system as host byte order The sender and the receiver must agree on the order in which the bytes of these multi-byte field transmitted: specify network byte order, which is big-endian byte ordering

Byte Order Functions #include <netinet.h> /* Host to network */ uint16_t htons(uint16_t host16bitvalue) Converts a 16-bit integer from host to network byte order uint32_t htonl(uint32_t host32bitvalue) Converts a 32-bit integer from host to network byte order Both return: value in network byte order /* Network to host */ uint16_t ntohs(uint16_t net16bitvalue) uint32_t ntohl(uint32_t net32bitvalue) Both return: value in host byte order

When do we use hton/ntoh functions? Use hton the port number in struct sockaddr_in If we create a custom struct to hold our headers and data Sending our data through send() and recv() functions E.g., if our first struct member is a 2-byte header, and sender/receiver have different memory orderings, number would look very different to each machine

Address Conversion Functions #include <arpa/inet.h> in_addr_t inet_addr(const char *strptr); /* return 32-bit binary network byte ordered IPv4 address; INADDR_NONE if error, deprecated and replaced by inet_aton() */ char *inet_ntoa(struct in_addr inaddr); /* returns: pointer to dotted-decimal string */