The document discusses sockets and the client-server model for interprocess communication. It describes what sockets are, the different types of sockets (STREAM, DATAGRAM, RAW), and how they are used for reliable and unreliable communication between processes. It provides code examples for creating, connecting, sending, receiving and closing sockets in both client and server applications using TCP and UDP. Key system calls for sockets like socket(), bind(), listen(), accept(), connect(), send(), recv(), close() are also explained.
Socket programming allows processes to communicate over a network. Key aspects include:
- Demultiplexing packets into processes using port numbers
- Converting between host and network byte order
- Sockets representing an endpoint for communication and identified by address/port pairs
- Functions for binding addresses, listening for connections, accepting connections, and sending/receiving data over established sockets.
What is Socket Programming in Python | EdurekaEdureka!
This document discusses socket programming in Python. It covers what sockets are, how to create them in Python, common port numbers and protocols, important socket methods, the roles of clients and servers in communication, and how to transfer Python objects using sockets and the pickle module.
Sockets allow for two-way communication between hosts in a network. There are two types of sockets: server sockets and client sockets. Server sockets wait for connection requests from clients, while client sockets are used to send and receive data from servers. Sockets provide input and output streams for transmission of data between endpoints.
This document discusses socket programming concepts in Java including server-client communication using sockets, the InetAddress class and its methods like getLocalHost(), getByName(), and getAllByName(), and the Socket and ServerSocket classes. It provides code examples to demonstrate how to use these classes and methods to establish connections between a client and server and exchange data over the network.
OAuth 2.0 is an authorization framework that allows third party applications to access user data without requiring username and passwords. It works by granting limited access tokens to third party apps after obtaining user consent. Many major tech companies use OAuth 2.0 including Facebook, Google, Twitter, and Microsoft. There are different OAuth 2.0 flows depending on the type of application, with the Authorization Code Grant and Implicit Grant being most common. It provides benefits like integration of third party apps and limited scope access, but also has potential drawbacks around complexity, interoperability, and security.
When we desire a communication between two applications possibly running on different machines, we need sockets. This presentation aims to provide knowledge of basic socket programming to undergraduate students. Basically, this presentation gives the importance of socket in the area of networking and Unix Programming. The presentation of Topic (Sockets) has designed according to the Network Programming Subject, B.Tech, 6th Semester syllabus of Punjab Technical University Kapurthala, Punjab.
The Internet Control Message Protocol (ICMP) allows devices on an IP network to send error and control messages to other devices to report issues or unexpected network conditions. It provides communication between IP layers to facilitate troubleshooting by transmitting error messages with a type and code field as well as checksum for verification. Common ICMP message types include queries to request information and error messages sent in response to problems with IP datagrams.
The document discusses address resolution protocol (ARP) which maps logical IP addresses to physical MAC addresses on a local area network. It explains that ARP broadcasts a request to find the MAC address associated with a given IP address, and the device with that IP address responds with its MAC. This dynamic address mapping is stored in an ARP cache for future use. It also describes how different network protocols may use ARP or similar methods to perform address mapping between logical and physical addresses.
Overview of SCTP (Stream Control Transmission Protocol)Peter R. Egli
Overview of SCTP (Stream Control Transmission Protocol), outlining the main features and capabilities of SCTP.
SCTP is a transport protocol that overcomes many of the shortcomings of TCP, namely head-of-line blocking and stream-oriented transmission.
SCTP supports multiple streams within a connection and preserves boundaries of application messages thus greatly simplifying communication.
Additionally, SCTP supports multi-homing which increases availability in applications with high reliability demands.
SCTP inherits much of the congestion, flow and error control mechanisms of TCP.
SCTP has its roots in telecom carrier networks for use in transitional voice over IP scenarios.
However, SCTP is generic so that it is applicable in many enterprise applications as well.
HTTPS is an encrypted version of HTTP that aims to secure communications over the internet. It uses SSL/TLS protocols to encrypt data transmitted between a client and server. This prevents sensitive information like passwords and credit cards from being accessed or altered by unauthorized parties when sent over the internet. HTTPS provides authentication of the server and encryption of data transmitted, addressing limitations of the unsecured HTTP protocol.
SSH is a protocol for secure remote access to a machine over untrusted networks.
SSH is a replacement for telnet, rsh, rlogin and can replace ftp.
Uses Encryption.
SSH is not a shell like Unix Bourne shell and C shell (wildcard expansion and command interpreter)
Socket programming allows applications to communicate over a network. Sockets provide an interface between applications and the network. There are two main types of sockets: SOCK_STREAM for reliable, ordered connections and SOCK_DGRAM for unreliable datagrams. A socket is created with the socket() call and configured with bind() and connect()/listen()+accept() for servers and clients respectively. Data is sent and received with send()/recv() or sendto()/recvfrom().
This document provides an overview and roadmap for a course on programming TCP/IP with sockets. The course covers important concepts on day one and then focuses each subsequent day on specific socket routines, library routines, sample client/server code, and VMS specifics. Slides and source code for the course are available via anonymous FTP from the listed hosts and directories.
Socket programming in C/C++ allows processes to communicate over a network. It involves creating a socket, binding it to an IP address and port, listening/accepting connections, and sending/receiving data. TCP provides connection-oriented reliable communication using functions like socket(), bind(), listen(), accept(), connect(), send(), recv(). UDP provides connectionless datagram communication using functions like socket(), bind(), sendto(), recvfrom(). Multicasting enables one-to-many communication using options like IP_MULTICAST_LOOP and IP_ADD_MEMBERSHIP.
Socket programming in Java allows applications to communicate over the internet. Sockets are endpoints for communication that are identified by an IP address and port number. A socket connection is established between a client and server socket. The server creates a welcoming socket to accept client connection requests, then a separate connection socket to communicate with that client. Data can be sent bidirectionally over the connected sockets as input/output streams. UDP uses datagram sockets without a connection, requiring the explicit destination address on each message.
Overview of the SSH protocol.
SSH (Secure SHell) is a secure replacement for TELNET, rcp, rlogin, rsh (for login, remote execution of
commands, file transfer).
Security-wise SSH provides confidentiality (nobody can read the message content), integrity (guarantee that data is unaltered in transit) and authentication (of client and server). This provides protection against many of the possible attack vectors like IP spoofing, DNS spoofing, Password interception and eavesdropping.
SSH exists in 2 versions. SSH-2 fixes some of the shortcomings of SSH-1 so it should be used in place of SSH-1.
SSH also comes with features that in itself raise security concerns like tunneling and port forwarding.
The overview on Socket Programming that will lead you how to program with a short example of programming which is in slide. With the help of this you can understand about network programming.
Port numbers are used to identify protocols and applications using the TCP/IP protocol suite. Some common port numbers and their associated protocols include port 80 for HTTP, port 443 for HTTPS, port 25 for SMTP email, and port 53 for DNS. Port numbers help direct network traffic to the appropriate application or service.
The document discusses subnet masks and how they are used to separate the network and host portions of an IP address. A subnet mask contains a binary pattern of ones and zeros that is applied using Boolean algebra to determine if an IP address is on the local network or needs to be routed externally. Default subnet masks exist for each address class, and their function is to filter out bits and identify the network address portion of a destination IP.
PHP is a server-side scripting language commonly used for web development. It allows developers to add dynamic content and functionality to websites. PHP code is executed on the server and the results are sent to the browser. This document provides an introduction to key PHP concepts like variables, operators, functions, forms, and GET/POST requests.
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...rahul kundu
The document defines HTTP and HTTPS. HTTP is the Hypertext Transfer Protocol that provides communication between web browsers and servers. It is unsecured and transmits data in plain text. HTTPS is HTTP secured with SSL/TLS encryption to provide security. Key differences are that HTTPS uses port 443 instead of HTTP's port 80, establishes an encrypted channel, and verifies servers with certificates to protect against attacks.
Writing Wireshark Filter Expression For Capturing PacketsXafran Marwat
This document summarizes the use of Wireshark filters to analyze network traffic. It describes capturing TCP packets to and from Facebook during login, analyzing flags like SYN and PSH. It also captures HTTP traffic to Facebook and traffic to a video streaming site Playit.pk, analyzing packet counts and flags. Graphs show packet counts over time for PSH flag and a histogram of packet sizes.
The document discusses network programming with sockets. It outlines basic socket programming concepts like client-server models, TCP and UDP services, and BSD sockets. It then describes key socket functions for creation and setup, establishing connections, sending/receiving data, and tearing down connections.
HTTP is the protocol that powers the web. It uses a request-response model where clients make requests that servers respond to. Common request methods include GET, POST, HEAD, PUT, DELETE, and OPTIONS. Responses include status codes like 200 for OK and content types. HTTP 1.1 added features like persistent connections and chunked encoding. Cookies are used to maintain statelessness. HTTPS uses SSL/TLS to secure HTTP connections with encryption, server authentication, and integrity.
This document discusses various data link control protocols. It covers framing, flow and error control, and specific protocols like HDLC and PPP. Framing involves adding structure like headers and trailers to organize data into packets. Flow and error control techniques like stop-and-wait ARQ and sliding window protocols are used to ensure reliable transmission over noisy channels. HDLC is a widely used bit-oriented protocol that defines frame structures and error control. PPP is a point-to-point protocol commonly used for dial-up internet access.
The document discusses I/O multiplexing using select and poll functions. It introduces select which allows a process to check if one or more file descriptors are ready for certain I/O conditions (e.g. reading, writing). Select blocks until one of the descriptors satisfies the specified conditions. It also describes how to use select to check read/write readiness of input/output devices and sockets. The document then rewrites an example client program to use select instead of separate system calls, allowing it to simultaneously wait for input from a socket or standard input.
Overview of socket API.
A network socket is an interface for an application to connect to a host‘s network stack (part of the OS). Sockets provide an abstraction of the network. Applications use the transport services available on the socket interface for communication with a peer application.
Transport protocol such as TCP, UDP or SCTP offer different levels of service. TCP for example provides reliable stream-oriented transport service while UDP more reflects the best-effort kind of service provided by the underlying IP protocol layer.
Sockets are bound to a transport address. For TCP/IP sockets this means an IP address and port number.
Sockets provide only very basic data transport services without any higher level functions like parameter marshaling or serialization. These functions have to be performed by the applications. These functions are often hidden in middleware platforms like distributed object technologies (CORBA, RMI, DCOM) or web service frameworks (WCF, JAX-WS).
Multicast sockets make the IP multicast capability accessible to applications. Multicast sockets are often used for streaming services where multiple applications are recipients of the same data packets.
The document discusses address resolution protocol (ARP) which maps logical IP addresses to physical MAC addresses on a local area network. It explains that ARP broadcasts a request to find the MAC address associated with a given IP address, and the device with that IP address responds with its MAC. This dynamic address mapping is stored in an ARP cache for future use. It also describes how different network protocols may use ARP or similar methods to perform address mapping between logical and physical addresses.
Overview of SCTP (Stream Control Transmission Protocol)Peter R. Egli
Overview of SCTP (Stream Control Transmission Protocol), outlining the main features and capabilities of SCTP.
SCTP is a transport protocol that overcomes many of the shortcomings of TCP, namely head-of-line blocking and stream-oriented transmission.
SCTP supports multiple streams within a connection and preserves boundaries of application messages thus greatly simplifying communication.
Additionally, SCTP supports multi-homing which increases availability in applications with high reliability demands.
SCTP inherits much of the congestion, flow and error control mechanisms of TCP.
SCTP has its roots in telecom carrier networks for use in transitional voice over IP scenarios.
However, SCTP is generic so that it is applicable in many enterprise applications as well.
HTTPS is an encrypted version of HTTP that aims to secure communications over the internet. It uses SSL/TLS protocols to encrypt data transmitted between a client and server. This prevents sensitive information like passwords and credit cards from being accessed or altered by unauthorized parties when sent over the internet. HTTPS provides authentication of the server and encryption of data transmitted, addressing limitations of the unsecured HTTP protocol.
SSH is a protocol for secure remote access to a machine over untrusted networks.
SSH is a replacement for telnet, rsh, rlogin and can replace ftp.
Uses Encryption.
SSH is not a shell like Unix Bourne shell and C shell (wildcard expansion and command interpreter)
Socket programming allows applications to communicate over a network. Sockets provide an interface between applications and the network. There are two main types of sockets: SOCK_STREAM for reliable, ordered connections and SOCK_DGRAM for unreliable datagrams. A socket is created with the socket() call and configured with bind() and connect()/listen()+accept() for servers and clients respectively. Data is sent and received with send()/recv() or sendto()/recvfrom().
This document provides an overview and roadmap for a course on programming TCP/IP with sockets. The course covers important concepts on day one and then focuses each subsequent day on specific socket routines, library routines, sample client/server code, and VMS specifics. Slides and source code for the course are available via anonymous FTP from the listed hosts and directories.
Socket programming in C/C++ allows processes to communicate over a network. It involves creating a socket, binding it to an IP address and port, listening/accepting connections, and sending/receiving data. TCP provides connection-oriented reliable communication using functions like socket(), bind(), listen(), accept(), connect(), send(), recv(). UDP provides connectionless datagram communication using functions like socket(), bind(), sendto(), recvfrom(). Multicasting enables one-to-many communication using options like IP_MULTICAST_LOOP and IP_ADD_MEMBERSHIP.
Socket programming in Java allows applications to communicate over the internet. Sockets are endpoints for communication that are identified by an IP address and port number. A socket connection is established between a client and server socket. The server creates a welcoming socket to accept client connection requests, then a separate connection socket to communicate with that client. Data can be sent bidirectionally over the connected sockets as input/output streams. UDP uses datagram sockets without a connection, requiring the explicit destination address on each message.
Overview of the SSH protocol.
SSH (Secure SHell) is a secure replacement for TELNET, rcp, rlogin, rsh (for login, remote execution of
commands, file transfer).
Security-wise SSH provides confidentiality (nobody can read the message content), integrity (guarantee that data is unaltered in transit) and authentication (of client and server). This provides protection against many of the possible attack vectors like IP spoofing, DNS spoofing, Password interception and eavesdropping.
SSH exists in 2 versions. SSH-2 fixes some of the shortcomings of SSH-1 so it should be used in place of SSH-1.
SSH also comes with features that in itself raise security concerns like tunneling and port forwarding.
The overview on Socket Programming that will lead you how to program with a short example of programming which is in slide. With the help of this you can understand about network programming.
Port numbers are used to identify protocols and applications using the TCP/IP protocol suite. Some common port numbers and their associated protocols include port 80 for HTTP, port 443 for HTTPS, port 25 for SMTP email, and port 53 for DNS. Port numbers help direct network traffic to the appropriate application or service.
The document discusses subnet masks and how they are used to separate the network and host portions of an IP address. A subnet mask contains a binary pattern of ones and zeros that is applied using Boolean algebra to determine if an IP address is on the local network or needs to be routed externally. Default subnet masks exist for each address class, and their function is to filter out bits and identify the network address portion of a destination IP.
PHP is a server-side scripting language commonly used for web development. It allows developers to add dynamic content and functionality to websites. PHP code is executed on the server and the results are sent to the browser. This document provides an introduction to key PHP concepts like variables, operators, functions, forms, and GET/POST requests.
Hypertext transfer protocol and hypertext transfer protocol secure(HTTP and H...rahul kundu
The document defines HTTP and HTTPS. HTTP is the Hypertext Transfer Protocol that provides communication between web browsers and servers. It is unsecured and transmits data in plain text. HTTPS is HTTP secured with SSL/TLS encryption to provide security. Key differences are that HTTPS uses port 443 instead of HTTP's port 80, establishes an encrypted channel, and verifies servers with certificates to protect against attacks.
Writing Wireshark Filter Expression For Capturing PacketsXafran Marwat
This document summarizes the use of Wireshark filters to analyze network traffic. It describes capturing TCP packets to and from Facebook during login, analyzing flags like SYN and PSH. It also captures HTTP traffic to Facebook and traffic to a video streaming site Playit.pk, analyzing packet counts and flags. Graphs show packet counts over time for PSH flag and a histogram of packet sizes.
The document discusses network programming with sockets. It outlines basic socket programming concepts like client-server models, TCP and UDP services, and BSD sockets. It then describes key socket functions for creation and setup, establishing connections, sending/receiving data, and tearing down connections.
HTTP is the protocol that powers the web. It uses a request-response model where clients make requests that servers respond to. Common request methods include GET, POST, HEAD, PUT, DELETE, and OPTIONS. Responses include status codes like 200 for OK and content types. HTTP 1.1 added features like persistent connections and chunked encoding. Cookies are used to maintain statelessness. HTTPS uses SSL/TLS to secure HTTP connections with encryption, server authentication, and integrity.
This document discusses various data link control protocols. It covers framing, flow and error control, and specific protocols like HDLC and PPP. Framing involves adding structure like headers and trailers to organize data into packets. Flow and error control techniques like stop-and-wait ARQ and sliding window protocols are used to ensure reliable transmission over noisy channels. HDLC is a widely used bit-oriented protocol that defines frame structures and error control. PPP is a point-to-point protocol commonly used for dial-up internet access.
The document discusses I/O multiplexing using select and poll functions. It introduces select which allows a process to check if one or more file descriptors are ready for certain I/O conditions (e.g. reading, writing). Select blocks until one of the descriptors satisfies the specified conditions. It also describes how to use select to check read/write readiness of input/output devices and sockets. The document then rewrites an example client program to use select instead of separate system calls, allowing it to simultaneously wait for input from a socket or standard input.
Overview of socket API.
A network socket is an interface for an application to connect to a host‘s network stack (part of the OS). Sockets provide an abstraction of the network. Applications use the transport services available on the socket interface for communication with a peer application.
Transport protocol such as TCP, UDP or SCTP offer different levels of service. TCP for example provides reliable stream-oriented transport service while UDP more reflects the best-effort kind of service provided by the underlying IP protocol layer.
Sockets are bound to a transport address. For TCP/IP sockets this means an IP address and port number.
Sockets provide only very basic data transport services without any higher level functions like parameter marshaling or serialization. These functions have to be performed by the applications. These functions are often hidden in middleware platforms like distributed object technologies (CORBA, RMI, DCOM) or web service frameworks (WCF, JAX-WS).
Multicast sockets make the IP multicast capability accessible to applications. Multicast sockets are often used for streaming services where multiple applications are recipients of the same data packets.
The document discusses socket programming and provides an overview of client-server applications using sockets. It describes how sockets allow for interprocess communication using the client-server model. The key steps for creating TCP and UDP client and server applications in both C and Java programming languages are outlined, including how to create sockets, bind sockets, connect sockets, send and receive data. Code examples of a TCP client and server application written in C are also provided.
This document provides an overview of Java sockets including how they allow for client-server communication over networks, the lifecycle of a socket server, and code examples for a socket server and clients. It discusses how sockets provide connection-oriented and connectionless services in Java using classes like ServerSocket and Socket. Diagrams depict the use cases and classes for a socket server that handles weather requests from multiple clients. Code for a WeatherSocketServer class and examples of client requests are also included.
The presentation given at MSBTE sponsored content updating program on 'Advanced Java Programming' for Diploma Engineering teachers of Maharashtra. Venue: Guru Gobind Singh Polytechnic, Nashik
Date: 22/12/2010
Session: Java Network Programming
This document discusses Java networking and client/server communication. A client machine makes requests to a server machine over a network using protocols like TCP and UDP. TCP provides reliable data transmission while UDP sends independent data packets. Port numbers map incoming data to running processes. Sockets provide an interface for programming networks, with ServerSocket and Socket classes in Java. A server program listens on a port for client connections and exchanges data through input/output streams. Servlets extend web server functionality by executing Java programs in response to client requests.
Network programming in java - PPT with Easy Programs and examples of Java InetAddress Class and java socket programming example.
Learn more @ http://java2all.com/technology/network-programming
This document discusses socket programming in Java. It begins by defining what a socket is - the combination of an IP address and port number used to uniquely identify an endpoint in a network connection. It then covers the basics of client-server socket programming using both TCP and UDP, including creating and using sockets, streams, and datagrams. Example code is provided for both TCP and UDP client and server implementations in Java using sockets to send and receive data. The document concludes with references for more information on socket programming.
This document discusses sockets and their use in networking applications. It begins with an overview of sockets, including that they provide an endpoint for network connections and are identified by both an IP address and port number. It then covers socket details for TCP and UDP, such as how TCP provides reliable connections while UDP is connectionless. The document concludes with examples of TCP and UDP client-server code using common socket functions like bind(), listen(), accept(), connect(), send(), and recv().
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.pptsenthilnathans25
Sockets provide an abstraction for interprocess communication by defining endpoints for sending and receiving data between applications over a network. There are two main types of sockets - stream sockets which provide reliable connected service using TCP, and datagram sockets which provide unreliable datagram service using UDP. Sockets use addresses, ports, and the socket abstraction to allow applications to communicate over a network in a standardized way. The select function allows monitoring multiple sockets for read or write readiness to avoid blocking behavior.
The document discusses socket programming and provides code examples for establishing sockets on both the client and server side. It explains that a socket is a communication mechanism that allows clients and servers to communicate locally or across networks. It then provides the key steps for setting up both connection-oriented and connectionless sockets, including creating and binding sockets, listening for connections, accepting connections, reading/writing data. It also discusses enhancements like allowing a server to handle multiple clients by forking new processes.
Application Layer and Socket Programmingelliando dias
The document discusses computer networking concepts related to the application layer and socket programming. It provides an overview of client-server applications and protocols, and describes how sockets allow applications to communicate over TCP and UDP. Specifically, it explains how servers can use sockets, binding, listening and accepting to establish TCP connections with clients. It also explains how clients can use sockets and connecting to communicate with servers. For UDP, it describes how servers can use sockets and binding to receive datagrams, while clients can use sockets and sending to communicate with servers.
Sockets provide an abstraction for network communication between processes. They define endpoints for connections that are identified by IP addresses and port numbers. There are two main types - stream sockets which provide reliable connected service using TCP, and datagram sockets which provide unreliable datagram service using UDP. To use sockets, an application creates a socket, binds it to an address, listens/accepts for incoming connections, and sends/receives data. Key functions include socket(), bind(), listen(), accept(), connect(), send(), and recv(). Select() allows monitoring multiple sockets to avoid blocking. Proper use requires consideration of addressing, port numbers, error handling, and blocking behavior.
This document provides an introduction to sockets, which provide an abstraction for interprocess communication. It describes the functions of sockets like defining endpoints, initiating and accepting connections, sending and receiving data, and terminating connections. It also discusses the different types of sockets (stream and datagram), addressing with clients and servers, and how sockets use addresses, ports, and the network. Finally, it covers concepts like blocking calls, non-blocking I/O, and using select() to check the status of file descriptors.
This document provides an introduction to sockets and their use for interprocess communication. It defines sockets as an abstraction layer between applications and network protocols that allows processes to establish connections for sending and receiving data. The document outlines the key functions of sockets like defining endpoints, initiating and accepting connections, sending and receiving data, and terminating connections. It also describes the different types of sockets for reliable stream-based and unreliable datagram-based communication. Addressing, ports, and the client-server model are explained at a high level. Code snippets demonstrate how to create, bind, listen for, and accept connections on both the client and server side.
Socket programming allows two programs to communicate over a network. It uses file descriptors and structs like sockaddr to define endpoints. There are two main socket types - stream sockets for TCP and datagram sockets for UDP. Key functions include socket(), bind(), listen(), accept(), send(), recv(), sendto(), and receivefrom(). A TCP server will create a socket, bind to a port, listen for connections, accept requests, and send/receive data. A TCP client connects and sends/receives similarly. A UDP server and client use sendto()/receivefrom() instead of connect().
The document discusses network programming and Java sockets. It introduces elements of client-server computing including networking basics like TCP, UDP and ports. It then covers Java sockets, explaining how to implement both a server and client using Java sockets. Code examples are provided of a simple server and client. The conclusion emphasizes that Java makes socket programming easier than other languages like C.
This document describes how to create UDP client-server programs in C using socket functions like sendto(), recvfrom(), and connect(). It discusses key differences between TCP and UDP, such as UDP being connectionless and unreliable. Example code is provided for a UDP echo server and client that exchange datagrams. Issues like lost datagrams, lack of flow control, and determining the outgoing interface are also covered. The document concludes by showing how to create a server that handles both TCP and UDP connections using select().
This document describes how to create a simple UDP echo server and client in C. It explains that UDP sockets are connectionless and datagrams are directly sent and received, unlike TCP sockets which are connection-oriented. The server code uses socket(), bind(), recvfrom(), and sendto() to receive datagrams from clients and echo them back. The client code uses socket(), sendto(), and recvfrom() to send messages to the server and receive the echoed responses. Running the server and testing it with netcat is demonstrated, and then a client program is provided to interact with the server instead of using netcat.
The document provides an overview of sockets and network programming in 3 paragraphs:
1) It introduces sockets as endpoints for connections between processes, with the socket represented by a descriptor integer. It describes how applications interface with sockets and the transport layer protocols like TCP and UDP.
2) It explains how connections between endpoints are defined by the host address (IP address) and port number. It provides details on port numbers and common port usages.
3) It outlines the main network transport protocols TCP and UDP, describing TCP as reliable and connection-based while UDP is unreliable and connectionless. It shows the typical client-server model using TCP.
This document discusses socket programming in C. It begins with an introduction to sockets, describing them as an interface between applications and networks that allows processes to communicate. It then covers the client-server model and types of sockets like stream and datagram. The main socket APIs are explained, including functions for creating, binding, listening, connecting, sending, receiving and closing sockets. Examples of socket programming with UDP and TCP are provided, showing the typical functions used in each case. The document concludes by noting that files can also be sent over sockets and models for handling multiple clients like process, thread and worker pools.
This document provides an overview of socket basics, including how sockets provide an endpoint for network connections and are identified by an IP address and port number. It describes the key functions for creating, binding, listening for, and accepting TCP and UDP sockets. TCP provides a reliable connected service while UDP is unreliable and connectionless. Port numbers and common services are also outlined.
The document discusses sockets and how they allow communication between processes on the same or different machines. It defines sockets, describes their history and key characteristics like being bidirectional endpoints. It covers socket domains, types (stream, datagram), common functions like socket(), bind(), listen(), accept(), connect(), recv(), send() and close(). It explains how these functions work for both TCP and UDP clients and servers.
Aspect-Oriented Software Development (AOSD) is a programming methodology that addresses limitations in object-oriented programming for modularizing cross-cutting concerns. AOSD uses aspects to encapsulate cross-cutting concerns so they can be separated from the core functionality. Aspects are automatically incorporated into the system by a weaver. This improves modularity and makes software easier to maintain and evolve over time.
CS554 � Introduction to Rational RoseJignesh Patel
Rational Rose is a visual modeling tool that allows users to graphically represent different views of a software system using diagrams. The document introduces various diagram types in Rational Rose, including use case diagrams, class diagrams, sequence diagrams, collaboration diagrams, activity diagrams, component diagrams, deployment diagrams, and statechart diagrams. Each diagram type shows a different perspective and can be used at different stages of the software development process to help with requirements, design, and communication.
CS521 Network Architecture II : Project ReviewJignesh Patel
The document provides an overview and review of three projects completed as part of a computer science course. Project 1 involved implementing a sliding window protocol for reliable data transfer over an unreliable network. Project 2 focused on designing and implementing a presence protocol for an instant messaging system. Project 3 required students to implement session messages from the SIP protocol specification. The reviews note that some groups struggled with design aspects, mixed application and protocol code, or failed to properly document their work. Overall, taking time for good design and understanding tools and specifications were emphasized as important lessons.
Hardware Approaches for Fast Lookup & ClassificationJignesh Patel
The document discusses hardware approaches for fast lookup and classification, specifically RAM-based and CAM-based approaches. CAMs (content-addressable memories) allow for very fast searches of an entire memory in a single clock cycle but have disadvantages of high cost and power consumption. TCAMs (ternary CAMs) can perform single clock cycle lookups for bitmask matches and are increasingly used in routers, while binary CAMs are used in switches.
The document describes the design of a link state routing protocol, including the representation of routers and networks as processes identified by IDs, the various packet types used in the protocol, and the data structures and state machines used to store routing and neighbor information and implement the protocol. It also discusses implementation requirements, issues, and how the protocol uses UDP to allow communication between routing processes on the same machine using ports.
Presentation given at the LangChain community meetup London
https://lu.ma/9d5fntgj
Coveres
Agentic AI: Beyond the Buzz
Introduction to AI Agent and Agentic AI
Agent Use case and stats
Introduction to LangGraph
Build agent with LangGraph Studio V2
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMAnchore
Over 70% of any given software application consumes open source software (most likely not even from the original source) and only 15% of organizations feel confident in their risk management practices.
With the newly announced Anchore SBOM feature, teams can start safely consuming OSS while mitigating security and compliance risks. Learn how to import SBOMs in industry-standard formats (SPDX, CycloneDX, Syft), validate their integrity, and proactively address vulnerabilities within your software ecosystem.
PyData - Graph Theory for Multi-Agent Integrationbarqawicloud
Graph theory is a well-known concept for algorithms and can be used to orchestrate the building of multi-model pipelines. By translating tasks and dependencies into a Directed Acyclic Graph, we can orchestrate diverse AI models, including NLP, vision, and recommendation capabilities. This tutorial provides a step-by-step approach to designing graph-based AI model pipelines, focusing on clinical use cases from the field.
Kubernetes Security Act Now Before It’s Too LateMichael Furman
In today's cloud-native landscape, Kubernetes has become the de facto standard for orchestrating containerized applications, but its inherent complexity introduces unique security challenges. Are you one YAML away from disaster?
This presentation, "Kubernetes Security: Act Now Before It’s Too Late," is your essential guide to understanding and mitigating the critical security risks within your Kubernetes environments. This presentation dives deep into the OWASP Kubernetes Top Ten, providing actionable insights to harden your clusters.
We will cover:
The fundamental architecture of Kubernetes and why its security is paramount.
In-depth strategies for protecting your Kubernetes Control Plane, including kube-apiserver and etcd.
Crucial best practices for securing your workloads and nodes, covering topics like privileged containers, root filesystem security, and the essential role of Pod Security Admission.
Don't wait for a breach. Learn how to identify, prevent, and respond to Kubernetes security threats effectively.
It's time to act now before it's too late!
מכונת קנטים המתאימה לנגריות קטנות או גדולות (כמכונת גיבוי).
מדביקה קנטים מגליל או פסים, עד עובי קנט – 3 מ"מ ועובי חומר עד 40 מ"מ. בקר ממוחשב המתריע על תקלות, ומנועים מאסיביים תעשייתיים כמו במכונות הגדולות.
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Anish Kumar
Presented by: Anish Kumar
LinkedIn: https://www.linkedin.com/in/anishkumar/
This lightning talk dives into real-world GenAI projects that scaled from prototype to production using Databricks’ fully managed tools. Facing cost and time constraints, we leveraged four key Databricks features—Workflows, Model Serving, Serverless Compute, and Notebooks—to build an AI inference pipeline processing millions of documents (text and audiobooks).
This approach enables rapid experimentation, easy tuning of GenAI prompts and compute settings, seamless data iteration and efficient quality testing—allowing Data Scientists and Engineers to collaborate effectively. Learn how to design modular, parameterized notebooks that run concurrently, manage dependencies and accelerate AI-driven insights.
Whether you're optimizing AI inference, automating complex data workflows or architecting next-gen serverless AI systems, this session delivers actionable strategies to maximize performance while keeping costs low.
Providing an OGC API Processes REST Interface for FME FlowSafe Software
This presentation will showcase an adapter for FME Flow that provides REST endpoints for FME Workspaces following the OGC API Processes specification. The implementation delivers robust, user-friendly API endpoints, including standardized methods for parameter provision. Additionally, it enhances security and user management by supporting OAuth2 authentication. Join us to discover how these advancements can elevate your enterprise integration workflows and ensure seamless, secure interactions with FME Flow.
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Safe Software
Jacobs has developed a 3D utility solids modelling workflow to improve the integration of utility data into 3D Building Information Modeling (BIM) environments. This workflow, a collaborative effort between the New Zealand Geospatial Team and the Australian Data Capture Team, employs FME to convert 2D utility data into detailed 3D representations, supporting enhanced spatial analysis and clash detection.
To enable the automation of this process, Jacobs has also developed a survey data standard that standardizes the capture of existing utilities. This standard ensures consistency in data collection, forming the foundation for the subsequent automated validation and modelling steps. The workflow begins with the acquisition of utility survey data, including attributes such as location, depth, diameter, and material of utility assets like pipes and manholes. This data is validated through a custom-built tool that ensures completeness and logical consistency, including checks for proper connectivity between network components. Following validation, the data is processed using an automated modelling tool to generate 3D solids from 2D geometric representations. These solids are then integrated into BIM models to facilitate compatibility with 3D workflows and enable detailed spatial analyses.
The workflow contributes to improved spatial understanding by visualizing the relationships between utilities and other infrastructure elements. The automation of validation and modeling processes ensures consistent and accurate outputs, minimizing errors and increasing workflow efficiency.
This methodology highlights the application of FME in addressing challenges associated with geospatial data transformation and demonstrates its utility in enhancing data integration within BIM frameworks. By enabling accurate 3D representation of utility networks, the workflow supports improved design collaboration and decision-making in complex infrastructure projects
➡ 🌍📱👉COPY & PASTE LINK👉👉👉 ➤ ➤➤ https://drfiles.net/
Wondershare Filmora Crack is a user-friendly video editing software designed for both beginners and experienced users.
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...Safe Software
The National Fuels Treatments Initiative (NFT) is transforming wildfire mitigation by creating a standardized map of nationwide fuels treatment locations across all land ownerships in the United States. While existing state and federal systems capture this data in diverse formats, NFT bridges these gaps, delivering the first truly integrated national view. This dataset will be used to measure the implementation of the National Cohesive Wildland Strategy and demonstrate the positive impact of collective investments in hazardous fuels reduction nationwide. In Phase 1, we developed an ETL pipeline template in FME Form, leveraging a schema-agnostic workflow with dynamic feature handling intended for fast roll-out and light maintenance. This was key as the initiative scaled from a few to over fifty contributors nationwide. By directly pulling from agency data stores, oftentimes ArcGIS Feature Services, NFT preserves existing structures, minimizing preparation needs. External mapping tables ensure consistent attribute and domain alignment, while robust change detection processes keep data current and actionable. Now in Phase 2, we’re migrating pipelines to FME Flow to take advantage of advanced scheduling, monitoring dashboards, and automated notifications to streamline operations. Join us to explore how this initiative exemplifies the power of technology, blending FME, ArcGIS Online, and AWS to solve a national business problem with a scalable, automated solution.
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfAlkin Tezuysal
As the demand for vector databases and Generative AI continues to rise, integrating vector storage and search capabilities into traditional databases has become increasingly important. This session introduces the *MyVector Plugin*, a project that brings native vector storage and similarity search to MySQL. Unlike PostgreSQL, which offers interfaces for adding new data types and index methods, MySQL lacks such extensibility. However, by utilizing MySQL's server component plugin and UDF, the *MyVector Plugin* successfully adds a fully functional vector search feature within the existing MySQL + InnoDB infrastructure, eliminating the need for a separate vector database. The session explains the technical aspects of integrating vector support into MySQL, the challenges posed by its architecture, and real-world use cases that showcase the advantages of combining vector search with MySQL's robust features. Attendees will leave with practical insights on how to add vector search capabilities to their MySQL systems.
Down the Rabbit Hole – Solving 5 Training RoadblocksRustici Software
Feeling stuck in the Matrix of your training technologies? You’re not alone. Managing your training catalog, wrangling LMSs and delivering content across different tools and audiences can feel like dodging digital bullets. At some point, you hit a fork in the road: Keep patching things up as issues pop up… or follow the rabbit hole to the root of the problems.
Good news, we’ve already been down that rabbit hole. Peter Overton and Cameron Gray of Rustici Software are here to share what we found. In this webinar, we’ll break down 5 training roadblocks in delivery and management and show you how they’re easier to fix than you might think.
Trends Artificial Intelligence - Mary MeekerClive Dickens
Mary Meeker’s 2024 AI report highlights a seismic shift in productivity, creativity, and business value driven by generative AI. She charts the rapid adoption of tools like ChatGPT and Midjourney, likening today’s moment to the dawn of the internet. The report emphasizes AI’s impact on knowledge work, software development, and personalized services—while also cautioning about data quality, ethical use, and the human-AI partnership. In short, Meeker sees AI as a transformative force accelerating innovation and redefining how we live and work.
The State of Web3 Industry- Industry ReportLiveplex
Web3 is poised for mainstream integration by 2030, with decentralized applications potentially reaching billions of users through improved scalability, user-friendly wallets, and regulatory clarity. Many forecasts project trillions of dollars in tokenized assets by 2030 , integration of AI, IoT, and Web3 (e.g. autonomous agents and decentralized physical infrastructure), and the possible emergence of global interoperability standards. Key challenges going forward include ensuring security at scale, preserving decentralization principles under regulatory oversight, and demonstrating tangible consumer value to sustain adoption beyond speculative cycles.
Domino IQ – What to Expect, First Steps and Use Casespanagenda
Webinar Recording: https://www.panagenda.com/webinars/domino-iq-what-to-expect-first-steps-and-use-cases/
HCL Domino iQ Server – From Ideas Portal to implemented Feature. Discover what it is, what it isn’t, and explore the opportunities and challenges it presents.
Key Takeaways
- What are Large Language Models (LLMs) and how do they relate to Domino iQ
- Essential prerequisites for deploying Domino iQ Server
- Step-by-step instructions on setting up your Domino iQ Server
- Share and discuss thoughts and ideas to maximize the potential of Domino iQ
4. Introduction to Sockets Why Sockets? Used for Interprocess communication. The Client-Server model Most interprocess communication uses client-server model Client & Server are two processes that wants to communicate with each other The Client process connects to the Server process, to make a request for information/services own by the Server. Once the connection is established between Client process and Server process, they can start sending / receiving information. What are Sockets? End-point of interprocess communication. An interface through which processes can send / receive information Socket
5. Introduction to Sockets What exactly creates a Socket? <IP address, Port #> tuple What makes a connection? {Source<IP address, Port #> , Destination <IP address, Port #>} i.e. source socket – destination socket pair uniquely identifies a connection. Example Server Client Client 192.168.0.1 192.168.0.2 192.168.0.2 80 1343 5488 Client 192.168.0.3 1343
6. Introduction to Sockets Socket Types STREAM – uses TCP which is reliable, stream oriented protocol DATAGRAM – uses UDP which is unreliable, message oriented protocol RAW – provides RAW data transfer directly over IP protocol (no transport layer) Sockets can use “ unicast ” ( for a particular IP address destination) “ multicast” ( a set of destinations – 224.x.x.x) “ broadcast ” (direct and limited) “ Loopback ” address i.e. 127.x.x.x
8. A generic TCP application algorithm for TCP client Find the IP address and port number of server Create a TCP socket Connect the socket to server (Server must be up and listening for new requests) Send/ receive data with server using the socket Close the connection algorithm for TCP server Find the IP address and port number of server Create a TCP server socket Bind the server socket to server IP and Port number (this is the port to which clients will connect) Accept a new connection from client returns a client socket that represents the client which is connected Send/ receive data with client using the client socket Close the connection with client
9. A generic UDP application algorithm for UDP client Find the IP address and port number of server Create a UDP socket Send/ receive data with server using the socket Close the connection algorithm for UDP server Find the IP address and port number of server Create a UDP server socket Bind the server socket to server IP and Port number (this is the port to which clients will send) Send/ receive data with client using the client socket Close the connection with client
11. Programming Client-Server in C The steps involved in establishing a socket on the client side are as follows: Create a socket with the socket() system call Connect the socket to the address of the server using the connect() system call Send and receive data using send() and recv() system calls. The steps involved in establishing a socket on the server side are as follows: Create a socket with the socket() system call Bind the socket to an address using the bind() system call. For a server socket on the Internet, an address consists of a port number on the host machine. Listen for connections with the listen() system call Accept a connection with the accept() system call. This call typically blocks until a client connects with the server. Send and receive data
12. Programming TCP Client in C #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> void error(char *msg){ perror(msg); exit(0);} int main(int argc, char *argv[]){ int sockfd, portno, n; struct sockaddr_in serv_addr; struct hostent *server; char buffer[256]; if (argc < 3) { fprintf(stderr,"usage %s hostname port\n", argv[0]); exit(0); } portno = atoi(argv[2]); sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockfd < 0) error("ERROR opening socket"); /* a structure to contain an internet address defined in the include file <netinet/in.h> */ struct sockaddr_in { short sin_family; /* should be AF_INET */ u_short sin_port; struct in_addr sin_addr; char sin_zero[8]; /* not used, must be zero */ }; struct in_addr { unsigned long s_addr; }; Client.c
13. Programming TCP Client in C #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> void error(char *msg){ perror(msg); exit(0);} int main(int argc, char *argv[]){ int sockfd, portno, n; struct sockaddr_in serv_addr; struct hostent *server; char buffer[256]; if (argc < 3) { fprintf(stderr,"usage %s hostname port\n", argv[0]); exit(0); } portno = atoi(argv[2]); sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockfd < 0) error("ERROR opening socket"); Client.c Socket System Call – create an end point for communication #include <sys/types.h> #include <sys/socket.h> int socket(int domain , int type , int protocol ); Returns a descriptor domain : selects protocol family e.g. PF_IPX, PF_X25, PF_APPLETALK type : specifies communication semantics e.g. SOCK_DGRAM, SOCK_RAW protocol : specifies a particular protocol to be used e.g. IPPROTO_UDP, IPPROTO_ICMP
14. Programming TCP Client in C server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr , server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = send(sockfd,buffer,strlen(buffer),0); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = recv(sockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("%s\n",buffer); close(sockfd); return 0; } Client.c Connect System Call – initiates a connection on a socket #include <sys/types.h> #include <sys/socket.h> int connect( int sockfd , const struct sockaddr * serv_addr , socklen_t addrlen ); Returns 0 on success sockfd : descriptor that must refer to a socket serv_addr : address to which we want to connect addrlen : length of serv_addr
15. Programming TCP Client in C server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr , server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = send(sockfd,buffer,strlen(buffer),0); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = recv(sockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("%s\n",buffer); close(sockfd); return 0; } Client.c Send System Call – send a message to a socket #include <sys/types.h> #include <sys/socket.h> int send( int s , const void * msg , size_t len , int flags ); Returns number of characters sent on success s : descriptor that must refer to a socket in connected state msg : data that we want to send len : length of data flags : use default 0. MSG_OOB, MSG_DONTWAIT
16. Programming TCP Client in C server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr , server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = send(sockfd,buffer,strlen(buffer),0); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = recv(sockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("%s\n",buffer); close(sockfd); return 0; } Client.c Recv System Call – receive a message from a socket #include <sys/types.h> #include <sys/socket.h> int recv( int s , const void * buff , size_t len , int flags ); Returns number of bytes received on success s : descriptor that must refer to a socket in connected state buff : data that we want to receive len : length of data flags : use default 0. MSG_OOB, MSG_DONTWAIT
17. Programming TCP Client in C server = gethostbyname(argv[1]); if (server == NULL) { fprintf(stderr,"ERROR, no such host\n"); exit(0); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr , server->h_length); serv_addr.sin_port = htons(portno); if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) error("ERROR connecting"); printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n = send(sockfd,buffer,strlen(buffer),0); if (n < 0) error("ERROR writing to socket"); bzero(buffer,256); n = recv(sockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("%s\n",buffer); close(sockfd); return 0; } Client.c Close System Call – close a socket descriptor #include <unistd.h> int close( int s ); Returns 0 on success s : descriptor to be closed
18. Programming TCP Server in C #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> void error(char *msg){ perror(msg); exit(0);} int main(int argc, char *argv[]){ int sockfd, newsockfd, portno, clilen; char buffer[256]; struct sockaddr_in serv_addr, cli_addr; int n; if (argc < 2) { fprintf(stderr,"ERROR, no port provided\n"); exit(1); } sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) error("ERROR opening socket"); bzero((char *) &serv_addr, sizeof(serv_addr)); portno = atoi(argv[1]); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); Server.c
19. Programming TCP Server in C if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) error("ERROR on accept"); bzero(buffer,256); n = recv(newsockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); n = send(newsockfd,"I got your message",18,0); if (n < 0) error("ERROR writing to socket"); close(newsockfd); close(sockfd); return 0; } Server.c Bind System Call – bind a name to a socket #include <sys/types.h> #include <sys/socket.h> int bind( int sockfd , const struct sockaddr * serv_addr , socklen_t addrlen ); Returns 0 on success sockfd : descriptor that must refer to a socket serv_addr : address to which we want to connect addrlen : length of serv_addr
20. Programming TCP Server in C if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) error("ERROR on accept"); bzero(buffer,256); n = recv(newsockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); n = send(newsockfd,"I got your message",18,0); if (n < 0) error("ERROR writing to socket"); close(newsockfd); close(sockfd); return 0; } Server.c Listen System Call – listen for connections on a socket #include <sys/types.h> #include <sys/socket.h> int listen( int s , int backlog ); Returns 0 on success s : descriptor that must refer to a socket backlog : maximum length the queue for completely established sockets waiting to be accepted addrlen : length of serv_addr
21. Programming TCP Server in C if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); listen(sockfd,5); clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if (newsockfd < 0) error("ERROR on accept"); bzero(buffer,256); n = recv(newsockfd,buffer,255,0); if (n < 0) error("ERROR reading from socket"); printf("Here is the message: %s\n",buffer); n = send(newsockfd,"I got your message",18,0); if (n < 0) error("ERROR writing to socket"); close(newsockfd); close(sockfd); return 0; } Server.c Accept System Call – accepts a connection on a socket #include <sys/types.h> #include <sys/socket.h> int accept( int sockfd , const struct sockaddr * addr , socklen_t addrlen ); Returns a non-negative descriptor on success sockfd : descriptor that must refer to a socket addr : filled with address of connecting entity addrlen : length of addr
22. Programming UDP Client in C The client code for a datagram socket client is the same as that for a stream socket with the following differences. the socket system call has SOCK_DGRAM instead of SOCK_STREAM as its second argument & IPPROTO_UDP instead of IPPROTO_TCP as its third argument. there is no connect() system call instead of send() and recv(), the client uses sendto() and recvfrom() sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); len = sizeof(struct sockaddr_in); while (1) { /* write */ n = sendto(sock,“Got your message\n",17, 0,(struct sockaddr *) &server, len); f (n < 0) error("sendto"); /* read */ n = recvfrom(sock,buf,1024,0,(struct sockaddr *)&from, len); if (n < 0) error("recvfrom"); }
23. Programming UDP Server in C Server code with a datagram socket is similar to the stream socket code with following differences. Servers using datagram sockets do not use the listen() or the accept() system calls. After a socket has been bound to an address, the program calls recvfrom() to read a message or sendto() to send a message. sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); len = sizeof(struct sockaddr_in); while (1) { /* read */ n = recvfrom(sock,buf,1024,0,(struct sockaddr *)&from, len); if (n < 0) error("recvfrom"); /* write */ n = sendto(sock,"Got your message\n",17, 0,(struct sockaddr *)&from, len); f (n < 0) error("sendto"); }
24. Programming Client-Server in C In case of Windows Everything in the code is same as described previously except the following differences You have to tell your compiler to link in the Winsock library, usually called wsock32.lib or winsock32.lib On Visual C++, this can be done through the Project menu, under Settings.... Click the Link tab, and look for the box titled "Object/library modules". Add "wsock32.lib" to that list. On Visual Studio .NET, add “wsock32.lib” under Project menu, Properties -> Linker -> Input -> Additional Dependencies #include <winsock.h> … .. void main(int argc,char *argv[]){ WSADATA wsda; // if this doesn’t work // WSAData wsda; // then try this WSAStartup(0x0101,&wsda); … .. WSACleanup(); closesocket(sockfd); }
26. Programming TCP Client-Server in Java All the classes related to sockets are in the java.net package, so make sure to import that package when you program sockets. All the input/output stream classes are in the java.io package, include this also How to open a socket? If you are programming a client, then you would create an object of Socket class Machine name is the machine you are trying to open a connection to, PortNumber is the port (a number) on which the server you are trying to connect to is running. select one that is greater than 1,023! Why?? Socket MyClient; try { MyClient = new Socket("Machine name", PortNumber); } catch (IOException e) { System.out.println(e); }
27. Programming TCP Client-Server in Java If you are programming a server, then this is how you open a socket: When implementing a server you also need to create a socket object from the ServerSocket in order to listen for and accept connections from clients. ServerSocket MyService; try { MyServerice = new ServerSocket(PortNumber); } catch (IOException e) { System.out.println(e); } Socket clientSocket = null; try { clientSocket = MyService.accept(); } catch (IOException e) { System.out.println(e); }
28. Programming TCP Client-Server in Java How to create an input stream? On the client side, you can use the DataInputStream class to create an input stream to receive response from the server: The class DataInputStream allows you to read lines of text and Java primitive data types in a portable way. It has methods such as read, readChar, readInt, readDouble, and readLine,. On the server side, you can use DataInputStream to receive input from the client: DataInputStream input; try { input = new DataInputStream(MyClient.getInputStream()); } catch (IOException e) { System.out.println(e); } DataInputStream input; try { input = new DataInputStream(clientSocket.getInputStream()); } catch (IOException e) { System.out.println(e); }
29. Programming TCP Client-Server in Java How to create an output stream? On the client side, you can create an output stream to send information to the server socket using the class PrintStream or DataOutputStream of java.io: The class PrintStream has methods for displaying textual representation of Java primitive data types. Its write and println methods are important. Also, you may want to use the DataOutputStream: Many of its methods write a single Java primitive type to the output stream. The method writeBytes is a useful one. PrintStream output; try { output = new PrintStream(MyClient.getOutputStream()); } catch (IOException e) { System.out.println(e); } DataOutputStream output; try { output = new DataOutputStream(MyClient.getOutputStream()); } catch (IOException e) { System.out.println(e); }
30. Programming TCP Client-Server in Java On the server side you can use the class PrintStream to send information to the client. Note: You can use the class DataOutputStream as mentioned previously. PrintStream output; try { output = new PrintStream(clientSocket.getOutputStream()); } catch (IOException e) { System.out.println(e); }
31. Programming TCP Client-Server in Java How to close sockets? You should always close the output and input stream before you close the socket. On the client side: On the server side: try { output.close(); input.close(); MyClient.close(); } catch (IOException e) { System.out.println(e); } try { output.close(); input.close(); clientSocket.close(); MyService.close(); } catch (IOException e) { System.out.println(e); }
32. Programming UDP Client-Server in Java How to open a datagram socket? If you are programming a client, then you would create an object of DatagramSocket class If you are programming a server, then this is how you open a socket: try { DatagramSocket socket = new DatagramSocket(); } catch (IOException e) { System.out.println(e); } DatagramSocket socket = null; try { socket = new DatagramSocket(4445); } catch (IOException e) { System.out.println(e); }
33. Programming UDP Client-Server in Java How to send/receive on Datagram sockets? On the client side, you can use the DatagramPacket class To send data To receive data byte[] buf = new byte[256]; InetAddress address = InetAddress.getByName(args[0]); DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4445); socket.send(packet); packet = new DatagramPacket(buf, buf.length); socket.receive(packet); String received = new String(packet.getData()); System.out.println(“Received from server: " + received);
34. Programming UDP Client-Server in Java How to send/receive on Datagram sockets? On the Server side, you can use the DatagramPacket class To receive data To send data How to close a Datagram socket? byte[] buf = new byte[256]; DatagramPacket packet = new DatagramPacket(buf, buf.length); socket.receive(packet); InetAddress address = packet.getAddress(); int port = packet.getPort(); packet = new DatagramPacket(buf, buf.length, address, port); socket.send(packet); socket.close();
35. References Man pages in Linux Accesssible through following command man 2 <system_call_name> E.g. man 2 socket “ Unix network programming” by Richard Stevens Beej’s guide to Network Programming http://beej.us/guide/bgnet/ The Java Tutorial – Custom Networking http://java.sun.com/docs/books/tutorial/networking/ Lecture notes of cs423 from Dr. Bob Cotter http://www.sce.umkc.edu/~cotterr/cs423_fs05/cs423_fs05_lectures.html