greg jernegan brandon simmons
Download
Skip this Video
Download Presentation
Socket Programming

Loading in 2 Seconds...

play fullscreen
1 / 10

Socket Programming - PowerPoint PPT Presentation


  • 55 Views
  • Uploaded on

Greg Jernegan Brandon Simmons. Socket Programming. The Beginning…. The problem Huge demand for internet enabled applications and programs that communicate over a network. Basic Level Server-client-media for communication Client makes request Server offers services for request.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Socket Programming' - gus


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
the beginning
The Beginning…
  • The problem
    • Huge demand for internet enabled applications and programs that communicate over a network.
  • Basic Level
    • Server-client-media for communication
      • Client makes request
      • Server offers services for request
what is socket programming
What is Socket Programming
  • Sockets provide an interface for programming networks at the transport layer.
    • Similar to file I/O
    • Communication is independent of programming language
      • This allows communication to exist among any languages even if they’re different
        • Example java talks to C++
how it works
How it works…
  • Server has one socket is bound to a specific port
  • Listens for connection request
    • Upon request if all goes well connection is made
  • After connection made the server gets a new socket bound to a different port
    • New port # needed so original socket can listen for connection request as well as serve the connected client
what that means
What that means…
  • Socket programming introduces a multitasking environment
    • More clients can be served at once with out a bottle neck or delay in service.
types of socket programming
Types of Socket Programming
  • SP can connected using both Connection Oriented server an client program and Connectionless
    • TCP beginning or UDP beginning
  • Programming may happen among many languages
    • in Python
      • Example: tcpserver.py and tcpclient.py
    • in Perl
      • Example: tcpserver.pl and tcpclient.pl
    • In C
      • Example: tcpserver.c and tcpclient.c
    • in Java
      • TCPServer.java and TCPClient.java
simple server in java
Simple Server in JAVA

// SimpleServer.java: A simple server program.

import java.net.*;

import java.io.*;

public class SimpleServer {

public static void main(String args[]) throws IOException {

// Register service on port 1254

ServerSocket s = new ServerSocket(1254);

Socket s1=s.accept(); // Wait and accept a connection

// Get a communication stream associated with the socket

OutputStream s1out = s1.getOutputStream();

DataOutputStream dos = new DataOutputStream (s1out);

// Send a string!

dos.writeUTF(“Hi there”);

// Close the connection, but not the server socket

dos.close();

s1out.close();

s1.close();

}

simple client in java
Simple Client in JAVA

// SimpleClient.java: A simple client program.

import java.net.*;

import java.io.*;

public class SimpleClient {

public static void main(String args[]) throws IOException {

// Open your connection to a server, at port 1254

Socket s1 = new Socket(“localhost”,1254);

// Get an input file handle from the socket and read the input

InputStream s1In = s1.getInputStream();

DataInputStreamdis = new DataInputStream(s1In);

String st = new String (dis.readUTF());

System.out.println(st);

// When done, just close the connection and exit

dis.close();

s1In.close();

s1.close();

}

}

commands
Commands
  • socket()creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it.
  • bind()is typically used on the server side, and associates a socket with a socket address structure, i.e. a specified local port number and IP address.
  • listen()is used on the server side, and causes a bound TCP socket to enter listening state.
  • connect()is used on the client side, and assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection.
  • accept() is used on the server side. It accepts a received incoming attempt to create a new TCP connection from the remote client, and creates a new socket associated with the socket address pair of this connection.
  • send(), recv(), write(), read(), sendto() and recvfrom(), are used for sending and receiving data to/from a remote socket.
  • close() causes the system to release resources allocated to a socket. In case of TCP, the connection is terminated.
  • gethostbyname(), gethostbyaddr() are used to resolve host names and addresses. IPv4 only.
  • select() is used to prune a provided list of sockets for those that are ready to read, ready to write, or that have errors.
  • poll() is used to check on the state of a socket in a set of sockets. The set can be tested to see if any socket can be written to, read from or if an error occurred.
  • getsockopt() is used to retrieve the current value of a particular socket option for the specified socket.
  • setsockopt() is used to set a particular socket option for the specified socket.
ad