Free Essay

Sockets

In:

Submitted By peshotanka
Words 4255
Pages 18
Sockets

1. Introduction
It has been a long way since we started our first tutorial. We learned about Visual Studio and many of its powerful features, we can outline a program and gather requirements, we implemented the fundamental programming concepts in the VB.NET and utilised the facilities that have already been provided for us by the .NET Framework. We can design and implement some very complex programs, but there is one thing that we still cannot do. We cannot make our program talk to another program on another computer. That is why in the following tutorial we are going to introduce the concept of sockets, which is one of the building blocks of the World Wide Web as we know it. Although it will not be strictly finance related as previous tutorials I will try and draw some parallel between the programming concepts and the ideas in the finance industry. Due to the volume, there will be no practical implementation after the concepts have been introduced. Nevertheless, a project will be given for the reader to practice what he/she has learned.

2. Sockets
A socket is a communications connection point (endpoint) that you can name and address in a network. They allow you to exchange information between processes on the same machine or across a network, distribute work to the most efficient machine, and they easily allow access to centralized data (Pic.dhe.ibm.com, 2013). If you imaging that your colleague is computer (computer) and you are also a computer, and he is very good at bond pricing, but it’s one of your strong sides, what you can do is give the work to him – the most efficient machine – and then ask him for the results. Sockets allow you to establish this communication. They are useful for both stand-alone and network applications.

Sockets are commonly used for client and server interaction. Typical system configuration places the server on one machine, with the clients on other machines. The clients connect to the server, exchange information, and then disconnect (Pic.dhe.ibm.com, 2013).
An Internet socket is characterized by a unique combination of local socket address and the type of protocol for exchanging information. If the type of protocol is Transmission Control Protocol (TCP) then the remote socket address is also included. The local socket address is characterized by the local IP address and a port number.

There are several types of sockets you can use, which are grouped in three main categories: Datagram sockets, Stream sockets, Raw sockets.

3.1. Datagram sockets
Datagram sockets are also known as connectionless sockets. However, that does not mean that they send messages by telepathy. What it means is that they do not establish a session, as we will see in the stream socket example, instead the server specifies its name where a client can send request. After that the client can send messages whenever it wants, without any control.

(Pic.dhe.ibm.com, 2013)

Connectionless sockets use User Datagram Protocol (UDP) instead of TCP/IP, which is used in stream sockets. However, because the UDP protocol is a connectionless protocol, UDP datagrams sent to the remote endpoint are not guaranteed to arrive, nor are they guaranteed to arrive in the same sequence in which they are sent. Applications that use UDP must be prepared to handle missing, duplicate, and out-of-sequence datagrams (Msdn.microsoft.com, 2013). In the following code example we will see how we can send message to ourselves, using UDP sockets. The code has been adapted from Msdn.microsoft.com (2013).

Example code:
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading

Sub Main()

''''''''''''''''''''Initialize listening & sending classes''''''''''''''''' TestReceiver.Main() 'Initializes the sender client TestSender.Main() 'Starts listening for incoming data

End Sub

'''''''''''''''''''''Setup receiving client''''''''''''' Public Class TestReceiver Public Shared Sub Main() Dim ListenThread As Thread 'Create a separate thread to listen for incoming data, helps to prevent the form from freezing up ListenThread = New Thread(AddressOf BeginListen) ListenThread.Start() End Sub

Private Shared Sub BeginListen() 'Used to create a loop for listening Dim done As Boolean = False Dim listener As New UdpClient(11000) 'Listen for incoming data from any IP address on port 11000 Dim groupEP As New IPEndPoint(IPAddress.Any, 11000) Try 'Setup an infinite loop While Not done Console.WriteLine("Waiting for broadcast") 'buffer for storing incoming bytes Dim bytes As Byte() 'Receive incoming bytes bytes = listener.Receive(groupEP) 'Specify where the packet was received from Console.WriteLine("Received broadcast from {0}", _ groupEP.ToString()) 'Convert bytes back to string and printing to console Console.WriteLine( _ Encoding.ASCII.GetString(bytes, 0, bytes.Length)) Console.WriteLine() End While Catch e As Exception Console.WriteLine(e.ToString()) Finally listener.Close() End Try End Sub End Class

''''''''''''''''''''Setup sender client''''''''''''''''' Public Class TestSender

Public Shared Sub Main() BeginSend() End Sub

Private Shared Sub BeginSend() Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)

'Send the data to localhost Dim broadcast As IPAddress = IPAddress.Parse("127.0.0.1")

'The message to be send from the client Dim str As String = "Message sent from UDP client: Hello Trader!" 'Converting the message to bytes Dim sendbuf As Byte() = Encoding.ASCII.GetBytes(str)

'Specifying where to send the message Dim ep As New IPEndPoint(broadcast, 11000)

'Sending the message s.SendTo(sendbuf, ep) End Sub End Class Questions: Can you send the message using another type of IP address, instead of the loopback (local host) address? Does your message always arrive, especially the first time you run you program and why does that happen? 3.2. Stream sockets
Stream sockets provide connection – oriented, sequenced and unduplicated flow of data, which has a well-defined mechanism for creating and destroying connections and for detecting errors. Traditionally they are implemented on top of TCP, so they can run across any network using the TCP/IP stack. Nevertheless, they can be implemented using SCTP, which is another type of network protocol.

(Pic.dhe.ibm.com, 2013)

The TCP protocol establishes a connection (session) with a remote endpoint and then uses that connection to send and receive data packets. TCP is responsible for ensuring that data packets are sent to the endpoint and assembled in the correct order when they arrive. To establish a TCP connection, you must know the address of the network device hosting the service you need and you must know the TCP port that the service uses to communicate (Msdn.microsoft.com, 2013).

Example code:
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading

Sub Main()

''''''''''''''''''''Initialize listening & sending classes''''''''''''''''' TcpTimeServer.Main() 'Initialise the time service TcpTimeClient.Main() 'Initialise the time client

End Sub

Public Class TcpTimeClient 'Specify the port number, which the client will try to connect to Private Const portNum As Integer = 13 'Specify the name of the name of the server Private Const hostName As String = "localhost"

Public Shared Sub Main() Try 'Initialise the client using the name of the server and the port number Dim client As New TcpClient(hostName, portNum)

'Open a stream where to receive the data Dim ns As NetworkStream = client.GetStream()

'Provide a buffer where to store the data in bytes Dim bytes(1024) As Byte

'Read the response from the server Dim bytesRead As Integer = ns.Read(bytes, 0, bytes.Length)

'Write the response from the server to the console Console.WriteLine("Time received at the client: " + Encoding.ASCII.GetString(bytes, 0, bytesRead))

'Close the connection client.Close()

Catch e As Exception Console.WriteLine(e.ToString()) End Try End Sub End Class 'TcpTimeClient

Public Class TcpTimeServer

Private Const portNum As Integer = 13

Public Shared Sub Main() Dim ListenThread As Thread 'Create a separate thread to listen for incoming data, helps to prevent the program from freezing up ListenThread = New Thread(AddressOf EstablishServer) ListenThread.Start() End Sub Private Shared Sub EstablishServer()

Dim done As Boolean = False

'The the IP address of the server Dim ipAddress As IPAddress = Dns.GetHostEntry("localhost").AddressList(0)

'Creates an instance of the TcpListener class by providing a local IP address and port number. Dim listener As New TcpListener(ipAddress, portNum)

'Start listening listener.Start()

'Set up an infinate loop While Not done Console.Write("Waiting for connection...")

'First accept the client Dim client As TcpClient = listener.AcceptTcpClient()

Console.WriteLine("Connection accepted.")

'Write to the client Dim ns As NetworkStream = client.GetStream()

'Convert the String Date and Time into bytes Dim byteTime As Byte() = _ Encoding.ASCII.GetBytes(DateTime.Now.ToString())

Try 'Write to the client ns.Write(byteTime, 0, byteTime.Length)

'Close the stream ns.Close()

'Close the connection with the client client.Close() Catch e As Exception Console.WriteLine(e.ToString()) End Try End While

'Stop listening for incoming requests listener.Stop() End Sub End Class 'TcpTimeServer

Questions: Can you identify the extra steps that occur, in order to establish a connection and close then connection?

3.3. Raw sockets
As we have seen in previous examples our sockets use a protocol in the network transport layer that takes care of how the packets are send and received. In addition, we as users cannot see this information. In contrast, raw sockets allow us to receive raw packets that include all the header information, which we can then access. When transmitting packets, the automatic addition of a header may be a configurable option of the socket. One reason why we might need this extra information is for troubleshooting applications that need to examine IP packets and headers in detail (Msdn.microsoft.com, 2013). Windows introduced support for raw sockets in the Winsock interface, however, this raised a lot of controversy, since a common use for raw sockets is to perform TCP reset attacks. Three years after that, Microsoft limited Winsock’s support for raw sockets in a non-removable hotfix and did not offer further support or workaround (Seclists.org, 2013). Considering the above information, we will not explore raw sockets any further than this.

3. Sockets in your Application
Once you start to make large scale applications you will have to consider one more factor when choosing the right socket for your program. There are two type of Client/Server connections in the context of your application synchronous and asynchronous and in the following two sections we will examine the advantages and disadvantages of both of them.

4.4. Synchronous Client/Server
Synchronous sockets suspend the execution of the application until a connection request is received on the socket. In the following code you will see how calling the Accept() method the server will cause the application to freeze and not establish the test client. The application will wait until someone has tried to connect to the server.

Example code: Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading

Sub Main()

SynchronousSocketListener.StartServer() SynchronousSocketClient.StartClient()

End Sub Public Class SynchronousSocketClient Public Shared Sub StartClient() ' Data buffer for incoming data. Dim bytes(1024) As Byte

' Connect to a remote device.

' Establish the remote endpoint for the socket. ' This example uses port 11000 on the local computer. Dim ipHostInfo As IPHostEntry = Dns.Resolve(Dns.GetHostName()) Dim ipAddress As IPAddress = ipHostInfo.AddressList(0) Dim remoteEP As New IPEndPoint(ipAddress, 11000)

' Create a TCP/IP socket. Dim sender As New Socket(AddressFamily.InterNetwork, _ SocketType.Stream, ProtocolType.Tcp)

' Connect the socket to the remote endpoint. sender.Connect(remoteEP)

Console.WriteLine("Client Socket connected to {0}", _ sender.RemoteEndPoint.ToString())

' Encode the data string into a byte array. Dim msg As Byte() = _ Encoding.ASCII.GetBytes("This is a test<EOF>")

' Send the data through the socket. Dim bytesSent As Integer = sender.Send(msg)

' Receive the response from the remote device. Dim bytesRec As Integer = sender.Receive(bytes) Console.WriteLine("Echoed test received at client = {0}", _ Encoding.ASCII.GetString(bytes, 0, bytesRec))

' Release the socket. sender.Shutdown(SocketShutdown.Both) sender.Close() End Sub

End Class 'SynchronousSocketClient Public Class SynchronousSocketListener

' Incoming data from the client. Public Shared data As String = Nothing

Public Shared Sub StartServerFromThread() Dim ListenThread As Thread 'Create a separate thread to listen for incoming data, helps to prevent the program from freezing up ListenThread = New Thread(AddressOf StartServer) ListenThread.Start() End Sub

Public Shared Sub StartServer() ' Data buffer for incoming data. Dim bytes() As Byte = New [Byte](1024) {}

' Establish the local endpoint for the socket. ' Dns.GetHostName returns the name of the ' host running the application. Dim ipHostInfo As IPHostEntry = Dns.Resolve(Dns.GetHostName()) Dim ipAddress As IPAddress = ipHostInfo.AddressList(0) Dim localEndPoint As New IPEndPoint(ipAddress, 11000)

' Create a TCP/IP socket. Dim listener As New Socket(AddressFamily.InterNetwork, _ SocketType.Stream, ProtocolType.Tcp)

' Bind the socket to the local endpoint and ' listen for incoming connections.

listener.Bind(localEndPoint) listener.Listen(10)

' Start listening for connections. Console.WriteLine("Waiting for a connection...") ' Program is suspended while waiting for an incoming connection. Dim handler As Socket = listener.Accept() data = Nothing

' An incoming connection needs to be processed. While True bytes = New Byte(1024) {} Dim bytesRec As Integer = handler.Receive(bytes) data += Encoding.ASCII.GetString(bytes, 0, bytesRec) If data.IndexOf("<EOF>") > -1 Then Exit While End If End While ' Show the data on the console. Console.WriteLine("Text received : {0}", data) ' Echo the data back to the client. Dim msg As Byte() = Encoding.ASCII.GetBytes(data) handler.Send(msg) handler.Shutdown(SocketShutdown.Both) handler.Close() End Sub

End Class 'SynchronousSocketListener

However, if you start the application from the method StartServerFromThread() this will make your server application asynchronous, which will allow your code to call the method Accept() on a separate thread and initialise the test client on another one.

Synchronous server sockets are not suitable for applications that make heavy use of the network in their operation, since they lock may lock your application for a very long time. However, they can be suitable for simple network applications.

Note that, in order to make your application asynchronous you had to initialise and start threads yourself. This is easy now, but once you start coding large scale applications initialising, synchronising threads and preventing deadlocks, livelocks, etc. becomes a very difficult task. That is why the guys from Microsoft have provided you with an Application Programming Interface (API) that takes of this for you.

Questions: Were the TCP and UDP examples synchronous or asynchronous? Why didn’t they freeze up?

4.5. Asynchronous Client/Server
In contrast, asynchronous client socket does not suspend the application while waiting for network operations to complete. Instead, it uses the standard .NET Framework asynchronous programming model to process the network connection on one thread while the application continues to run on the original thread. In addition, they use multiple threads from the system thread pool to process network connections. One thread is responsible for initiating the sending or receiving of data; other threads complete the connection to the network device and send or receive the data. The following table shows the methods to begin and end an asynchronous socket (Winsocketdotnetworkprogramming.com, 2013).

Start Method | End Method | Description | BeginAccept() | EndAccept() | Accepts a client connection on a connection-oriented server socket and returns a Socket object for the client connection | BeginConnect() | EndConnect() | Initiates a client connection to the indicated server | BeginReceive() | EndReceive() | Receives data into the specified buffer on the connected socket | BeginReceiveFrom() | EndReceiveFrom() | Receives data into the specified buffer and returns the EndPoint from which the data originated | BeginSend() | EndSend() | Sends the given data buffer on the connected socket | BeginSendTo() | EndSendTo() | Sends the given data buffer to the specified destination |

An asynchronous server socket requires a method to begin accepting connection requests from the network, a callback method to handle the connection requests and begin receiving data from the network, and a callback method to end receiving the data. In addition, if your application needs to know the result of the operation, then a callback method is required (Msdn.microsoft.com, 2013).

Asynchronous sockets are appropriate for applications that make heavy use of the network or that cannot wait for network operations to complete before continuing.

In the following example the client code has been adapted from http://msdn.microsoft.com/en-us/library/bew39x2a(v=vs.110).aspx and the server code has been addpated from http://msdn.microsoft.com/en-us/library/fx6588te(v=vs.110).aspx

Example code:
Sub Main()

AsynchronousSocketListener.Main() AsynchronousClient.Main() End Sub Public Class AsynchronousSocketListener

' State object for reading client data asynchronously Private Class StateObject ' Client socket. Public workSocket As Socket = Nothing ' Size of receive buffer. Public Const BufferSize As Integer = 1024 ' Receive buffer. Public buffer(BufferSize) As Byte ' Received data string. Public sb As New StringBuilder End Class 'StateObject ' Thread signal. Public Shared allDone As New ManualResetEvent(False)

' This server waits for a connection and then uses asychronous operations to ' accept the connection, get data from the connected client, ' echo that data back to the connected client. ' It then disconnects from the client and waits for another client. Public Shared Sub Main() ' Data buffer for incoming data. Dim bytes() As Byte = New [Byte](1023) {}

' Establish the local endpoint for the socket. Dim ipHostInfo As IPHostEntry = Dns.Resolve(Dns.GetHostName()) Dim ipAddress As IPAddress = ipHostInfo.AddressList(0) Dim localEndPoint As New IPEndPoint(ipAddress, 11000)

' Create a TCP/IP socket. Dim listener As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

' Bind the socket to the local endpoint and listen for incoming connections. listener.Bind(localEndPoint) listener.Listen(100)

' Set the event to nonsignaled state. allDone.Reset()

' Start an asynchronous socket to listen for connections. Console.WriteLine("Waiting for a connection...") listener.BeginAccept(New AsyncCallback(AddressOf AcceptCallback), listener)

End Sub 'Main

Public Shared Sub AcceptCallback(ByVal ar As IAsyncResult) ' Get the socket that handles the client request. Dim listener As Socket = CType(ar.AsyncState, Socket) ' End the operation. Dim handler As Socket = listener.EndAccept(ar)

' Create the state object for the async receive. Dim state As New StateObject state.workSocket = handler handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, New AsyncCallback(AddressOf ReadCallback), state) End Sub 'AcceptCallback

Public Shared Sub ReadCallback(ByVal ar As IAsyncResult) Dim content As String = String.Empty

' Retrieve the state object and the handler socket ' from the asynchronous state object. Dim state As StateObject = CType(ar.AsyncState, StateObject) Dim handler As Socket = state.workSocket

' Read data from the client socket. Dim bytesRead As Integer = handler.EndReceive(ar)

If bytesRead > 0 Then ' There might be more data, so store the data received so far. state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead))

' Check for end-of-file tag. If it is not there, read ' more data. content = state.sb.ToString() If content.IndexOf("<EOF>") > -1 Then ' All the data has been read from the ' client. Display it on the console. Console.WriteLine("Read {0} bytes from socket. " + vbLf + " Data : {1}", content.Length, content) ' Echo the data back to the client. Send(handler, content) Else ' Not all data received. Get more. handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, New AsyncCallback(AddressOf ReadCallback), state) End If End If End Sub 'ReadCallback

Private Shared Sub Send(ByVal handler As Socket, ByVal data As String) ' Convert the string data to byte data using ASCII encoding. Dim byteData As Byte() = Encoding.ASCII.GetBytes(data)

' Begin sending the data to the remote device. handler.BeginSend(byteData, 0, byteData.Length, 0, New AsyncCallback(AddressOf SendCallback), handler) End Sub 'Send

Private Shared Sub SendCallback(ByVal ar As IAsyncResult) ' Retrieve the socket from the state object. Dim handler As Socket = CType(ar.AsyncState, Socket)

' Complete sending the data to the remote device. Dim bytesSent As Integer = handler.EndSend(ar) Console.WriteLine("Sent {0} bytes to client.", bytesSent)

handler.Shutdown(SocketShutdown.Both) handler.Close() ' Signal the main thread to continue. allDone.Set() End Sub 'SendCallback End Class 'AsynchronousSocketListener Public Class AsynchronousClient

' State object for receiving data from remote device. Private Class StateObject ' Client socket. Public workSocket As Socket = Nothing ' Size of receive buffer. Public Const BufferSize As Integer = 256 ' Receive buffer. Public buffer(BufferSize) As Byte ' Received data string. Public sb As New StringBuilder End Class 'StateObject

' The port number for the remote device. Private Const port As Integer = 11000

' ManualResetEvent instances signal completion. Private Shared connectDone As New ManualResetEvent(False) Private Shared sendDone As New ManualResetEvent(False) Private Shared receiveDone As New ManualResetEvent(False)

' The response from the remote device. Private Shared response As String = String.Empty

Public Shared Sub Main() ' Establish the remote endpoint for the socket. ' For this example use local machine. Dim ipHostInfo As IPHostEntry = Dns.Resolve(Dns.GetHostName()) Dim ipAddress As IPAddress = ipHostInfo.AddressList(0) Dim remoteEP As New IPEndPoint(ipAddress, port)

' Create a TCP/IP socket. Dim client As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

' Connect to the remote endpoint. client.BeginConnect(remoteEP, New AsyncCallback(AddressOf ConnectCallback), client)

' Wait for connect. connectDone.WaitOne()

' Send test data to the remote device. Send(client, "This is a test<EOF>") sendDone.WaitOne()

' Receive the response from the remote device. Receive(client) receiveDone.WaitOne()

' Write the response to the console. Console.WriteLine("Response received : {0}", response)

' Release the socket. client.Shutdown(SocketShutdown.Both) client.Close() End Sub 'Main

Private Shared Sub ConnectCallback(ByVal ar As IAsyncResult) ' Retrieve the socket from the state object. Dim client As Socket = CType(ar.AsyncState, Socket)

' Complete the connection. client.EndConnect(ar)

Console.WriteLine("Socket connected to {0}", client.RemoteEndPoint.ToString())

' Signal that the connection has been made. connectDone.Set() End Sub 'ConnectCallback

Private Shared Sub Receive(ByVal client As Socket)

' Create the state object. Dim state As New StateObject state.workSocket = client

' Begin receiving the data from the remote device. client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, New AsyncCallback(AddressOf ReceiveCallback), state) End Sub 'Receive

Private Shared Sub ReceiveCallback(ByVal ar As IAsyncResult)

' Retrieve the state object and the client socket ' from the asynchronous state object. Dim state As StateObject = CType(ar.AsyncState, StateObject) Dim client As Socket = state.workSocket

' Read data from the remote device. Dim bytesRead As Integer = client.EndReceive(ar)

If bytesRead > 0 Then ' There might be more data, so store the data received so far. state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead))

' Get the rest of the data. client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, New AsyncCallback(AddressOf ReceiveCallback), state) Else ' All the data has arrived; put it in response. If state.sb.Length > 1 Then response = state.sb.ToString() End If ' Signal that all bytes have been received. receiveDone.Set() End If End Sub 'ReceiveCallback

Private Shared Sub Send(ByVal client As Socket, ByVal data As String) ' Convert the string data to byte data using ASCII encoding. Dim byteData As Byte() = Encoding.ASCII.GetBytes(data)

' Begin sending the data to the remote device. client.BeginSend(byteData, 0, byteData.Length, 0, New AsyncCallback(AddressOf SendCallback), client) End Sub 'Send

Private Shared Sub SendCallback(ByVal ar As IAsyncResult) ' Retrieve the socket from the state object. Dim client As Socket = CType(ar.AsyncState, Socket)

' Complete sending the data to the remote device. Dim bytesSent As Integer = client.EndSend(ar) Console.WriteLine("Sent {0} bytes to server.", bytesSent)

' Signal that all bytes have been sent. sendDone.Set() End Sub 'SendCallback End Class 'AsynchronousClient

Questions: What will happen if you do not call an end method in your callback function?

4. Summary * You know what datagram sockets are and how to use them in VB.NET * You know what stream sockets are and how to use them in VB.NET * You are familiar with raw sockets * You can use synchronous sockets in VB.NET and you know what are the various advantages and disadvantages of using them * You can use asynchronous sockets in VB.NET and you know what are the various advantages and disadvantages of using them

5. Project
Implement a multi-client chat program that uses asynchronous TCP/IP sockets. In the server window you should a box where to specify the port you are listening on and a log window, which displays messages from the client. The client window should have a box where to specify the IP of the server you want to connect to and a box for the port number. You should be able to send messages from the client window to the server.
References:
* Msdn.microsoft.com. 2013. Using UDP Services. [online] Available at: http://msdn.microsoft.com/en-us/library/tst0kwb1(v=vs.110).aspx [Accessed: 11 Dec 2013] * Msdn.microsoft.com. 2013. Using TCP Services. [online] Available at: http://msdn.microsoft.com/en-us/library/k8azesy5(v=vs.110).aspx [Accessed: 12 Dec 2013]. * Msdn.microsoft.com. 2013. TCP/IP Raw Sockets (Windows). [online] Available at: http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548(v=vs.85).aspx [Accessed: 12 Dec 2013]. * Msdn.microsoft.com. 2013. Using an Asynchronous Client Socket. [online] Available at: http://msdn.microsoft.com/en-us/library/bbx2eya8(v=vs.110).aspx [Accessed: 13 Dec 2013]. * Msdn.microsoft.com. 2013. Using an Asynchronous Server Socket. [online] Available at: http://msdn.microsoft.com/en-us/library/5w7b7x5f(v=vs.110).aspx [Accessed: 13 Dec 2013]. * Pic.dhe.ibm.com. 2013. IBM i information center. [online] Available at: http://pic.dhe.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Frzab6%2Fhowdosockets.htm [Accessed: 11 Dec 2013]. * Seclists.org. 2013. Nmap Announce: Microsoft Tightens the Noose on Raw Sockets. [online] Available at: http://seclists.org/nmap-announce/2005/4 [Accessed: 12 Dec 2013]. * Winsocketdotnetworkprogramming.com. 2013. The information for asynchronous socket operations, asynchronous accept, asynchronous connect, asynchronous data transfer and canceling the pending asynchronous operations. [online] Available at: http://www.winsocketdotnetworkprogramming.com/serverlisteningnetworksocketdotnet9g.html [Accessed: 13 Dec 2013].

Similar Documents

Premium Essay

The Assembly Process

...The Splendor of the Assembly Process in Manufacturing Abstract The assembly process is both unique and versatile, and presents an interesting way to look at all manufacturing processes as a whole instead of individual pieces. By examining the different methods and materials that make up today’s products it will be shown how the assembly process is the most versatile and mandatory process in manufacturing. Examining the different methods and materials reveals the uniqueness of the assembly process and how it can literally be applied to any product, method, or material in manufacturing. This will also high light the importance of the advancement of the assembly process both past and present. Studying the industrial revolution provides key elements in how the manufacturing industry has become what it is today. From the invention of the flying shuttle to the innovation behind the assembly line, it can be determined that the development of assembly process machinery and technology is the key to the advancement of our economy and country as a whole. These minor ripples in the pool of industry ended up causing tsunamis and forever changing the landscape of the country as we know it. Looking back at the technological advancements of the industrial revolution it becomes clear that we are on the verge of yet another revolution in industry. The introduction of auto-CAD and the 3-D printer have already started the next wave in what is sure to become a tsunami in the...

Words: 2913 - Pages: 12

Free Essay

Communication

...Distributed Operating Systems Communication (II) Ewa Niewiadomska-Szynkiewicz ens@ia.pw.edu.pl Institute of Control and Computation Engineering Warsaw University of Technology E&IT Department, WUT DOS / Communication (II) – p. 1 Communication (II) 1. Message-oriented Communication 2. Stream-oriented Communication E&IT Department, WUT DOS / Communication (II) – p. 2 Message-oriented Communication – Introduction √ When it cannot be assumed that the receiving side is executing at the time a request (in RPC or RMI) is issued, alternative communication services are needed. The inherent synchronous nature of RPCs and RMIs, by which a client is blocked until its request has been processed, sometimes has to be replaced. Message-oriented communication is proposed. √ √ The message-passing paradigm is widely used approach for programming parallel machines, especially those with distributed memory. E&IT Department, WUT DOS / Communication (II) – p. 3 Message-passing Paradigm – Attributes Two key attributes characterizing the message-passing paradigm: √ it assumes a partitioned address space, √ it supports only explicit parallelization. The logical view of a machine supporting the message-passing paradigm consists of P processes, each with its own exclusive address space. E&IT Department, WUT DOS / Communication (II) – p. 4 Communication System (1) Assumption – communication system organized as follows: √ applications are executed...

Words: 3031 - Pages: 13

Free Essay

Jkjk

...Scapy ● ● ● ● ● ● What is Scapy Why use Scapy? Important concepts to keep in mind Crafting your first packet Sending and Receiving Packets/Frames Basic examples and dealing with the OS's TCP/IP stack using iptables Quick discussion of the Super Socket ● What is Scapy ● A Python framework used for crafting and transmitting packets. Capable of Sniffing or replaying packets for troubleshooting or fuzzing network services. Can be used as the interactive Python interpreter or the framework can be imported as a python module and used for further coding Everything is an object! ● ● ● Why use Scapy? ● Blue Team – – – – Test IDS/IPS Test Firewall Learn more about TCP/IP (down and dirty) Application response(Fuzzing) Fire teh lazorz (DOS/DDOS) More Fuzzing Penetration Testing ● Red Team – – – Important Concepts ● Everything is an Object – treat it as such – IP(), TCP(), UDP(), ICMP() help() - displays help ls() - displays packet classes lsc() - displays commands available to you ip=IP(src=”1.2.3.4”, dst=”google.com”) ip=IP() ip.src=”1.2.3.4” ip.dst=”google.com” ● Important commands to remember: – – – ● When assigning Field Values(either works) – – – – Important Concepts Continued ● Displaying Values of Variables – – – ls(ip) – shows what you have set and default vaules ip – shows only what you have set ip.show() - omits variable classes and default values packet=IP(dst=”1.2.3.4”)/TCP(flags=”S”,dport=443) frame=Ether(type=0x8100)/Dot1Q(vlan=99)/packet...

Words: 831 - Pages: 4

Free Essay

Assignment

...Overview • Socket Programming: how applications use the network Socket Programming EE 122: Intro to Communication Networks Vern Paxson TAs: Lisa Fowler, Daniel Killebrew, Jorge Ortiz – Sockets are a C-language programming interface between Layer 7 (applications) and Layer 4 (transport) – Interface is quite general and fairly abstract – Use of interface differs somewhat between clients & servers Materials with thanks to Sukun Kim, Artur Rivilis, Jennifer Rexford, Ion Stoica, and colleagues at Princeton and UC Berkeley 1 2 Socket: End Point of Communication • Sending message from one process to another – Message must traverse the underlying network Using Ports to Identify Services Server host 128.2.194.242 Client host Client • Process sends and receives through a “socket” – In essence, the doorway leading in/out of the house Service request for 128.2.194.242:80 (i.e., the Web server) OS Web server (port 80) Echo server (port 7) • Socket as an Application Programming Interface – Supports the creation of network applications User process User process Service request for 128.2.194.242:7 (i.e., the echo server) Client Web server (port 80) OS Echo server (port 7) socket Operating System socket Operating System 3 4 Knowing What Port Number To Use • Popular applications have “well-known ports” – E.g., port 80 for Web and port 25 for e-mail – Well-known ports listed at http://www.iana.org Or see /etc/services on Unix systems ...

Words: 1853 - Pages: 8

Premium Essay

Nt1310 Unit 3 Assignment

...ITITIU13142 ASSIGNMENT 1 1 REQUIREMENT • Refer to the section 2.7. ”Socket programming” in the book given at pages 165-167. • Understand, run, and explain the programs TCPclient.py and TCPserver.py (or TCPclient.java and TCPserver.java) 2 CODE 2.1 TCP CLIENT package tcp; import java.io.*; import java.net.*; public class tcpclient { public static void main(String argv[]) throws IOException { Socket c = new Socket("localhost", 1342); BufferedReader inuser = new BufferedReader(new InputStreamReader(System.in)); DataOutputStream outser = new DataOutputStream(c.getOutputStream()); BufferedReader inser = new BufferedReader(new InputStreamReader(c.getInputStream())); System.out.println("Send:...

Words: 1181 - Pages: 5

Free Essay

Tcp/Ip

...TCP/IP - Socket Programming Jim Binkley 1 sockets - overview sockets ◆ simple client - server model ◆ – – – look at tcpclient/tcpserver.c look at udpclient/udpserver.c tcp/udp contrasts “normal” master/slave setup for TCP ◆ inetd on UNIX - mother server ◆ some details - there are more... ◆ Jim Binkley 2 sockets in BSD world since early 80’s, 4.2 BSD ◆ client/server model ◆ “like” unix file i/o up to a point, can be redirected to stdin/stdout/stderr (on unix) ◆ sockets are dominant tcp/ip application API ◆ – – other API is System V TLI (OSI-based) winsock - windows variations on sockets » sockets in windows event-driven framework 3 Jim Binkley sockets ◆ basic definition - “endpoint of communication” allows connected streams (TCP) or discrete messages (UDP) between processes on same machine, cross network ◆ in o.s., really read/write data queues + TCP has connection Queue (server side) ◆ talk to “socket” with handle/sock descriptor ◆ Jim Binkley 4 kinds of sockets acc. to address family; i.e. how does addressing work ◆ IP address family -> IP addr, tcp/udp port ◆ traditional BSD families ◆ – TCP/IP (AF_INET; i.e., Internet) » TCP/UDP/”raw” (talk to IP) – – – Jim Binkley UNIX (intra-machine, pipes) XNS, and even APPLETALK, DECNET, IPX ... 5 sockets client handle read write read write server socket layer r/w queues tcp stack Jim Binkley 6 syscalls - TCP client/simple test server int s =...

Words: 1236 - Pages: 5

Free Essay

Google Tricks

... NT 1110 Lab 4 Task 1: LGA 1156, also known as Socket H[2][3] or H1, is an Intel desktop CPU socket. LGA stands for land grid array. Its incompatible successor is LGA 1155. LGA 1156, along with LGA 1366, were designed to replace LGA 775. Whereas LGA 775 processors connect to a northbridge using the Front Side Bus, LGA 1156 processors integrate the features traditionally located on a northbridge on the processor itself. The LGA 1156 socket allows the following connections to be made from the processor to the rest of the system: PCI-Express 2.0 ×16 for communication with a graphics card. Some processors allow this connection to be divided into two ×8 lanes to connect two graphics cards. Some motherboard manufacturers use Nvidia's NF200 chip to allow even more graphics cards to be used. DMI for communication with the Platform Controller Hub (PCH). This consists of a PCI-Express 2.0 ×4 connection. FDI for communication with the PCH. This consists of two DisplayPort connections. Two memory channels for communication with DDR3 SDRAM. The clock speed of the memory that is supported will depend on the processor. LGA 1156 socket and processors were discontinued sometime in 2012, along with LGA 1366.[4] Supported processors Code name | Brand name | Model (list) | Frequency | Cores/Threads | Max Memory Speed | Lynnfield...

Words: 1200 - Pages: 5

Free Essay

Motherboard Components and Form Factors

...phones, IPads, IPods, 3x USB power delivery for greater compatibility and extra power for USB devices, Patented DualBIOS, Easy BIOS setting for GPU overclocking, supports 6 devices without the need for drivers to be installed before being fully operational. AMD 770 Northbridge Chipset.: AMD AM3 Processor Support Based on the AMD 770 chipset, the MSI 770-G45 AMD motherboard supports AMD's latest generation Phenom II processors, as well as Athlon II and Sempron 100 series processors in AM3 socket. The purpose of the 770 Northbridge chipset on the motherboard is to link the computer system's hardware to the processor. Processors used in a AMD SB710 Southbridge Chipset: Socket AM3/AM2 Processors: AMD Turion II Neo, AMD Athlon, II Neo Processors (ASB2), AMD Turion Neo, AMD Athlon Neo, and AMD Sempron Processors (ASB1) The purpose of the motherboard for the AMD SB710 Southbrdge chipset is to control the processes that are going on within the computer's main frame system. Socket AM3 Connector: compatible with the AM3 and AM3+ processors which have 941 pins. Processor Clock Speed Internal Cache Bus Speed Architecture i7 3.7 GHz 1.5 MB 4.8 GHz Bloomfield i7 mobile 1.6 GHz 6.0 MB 2.5 GHz Clarksfield i5 3.46 GHz 8.0 MB 4.8 GHz Lynnfield i5 mobile 2.40 GHz 3 MB 2.5 GHz Arrandale i3 2.93 GHz...

Words: 594 - Pages: 3

Free Essay

Mmmmm

...the network, we are programming at the application layer • however, to decide which Java classes our programs should use, we need to understand how TCP and UDP differ UDP (User Datagram Protocol) • connectionless - sends independent packets of data, called datagram, from one computer to another with no guarantees about arrival • each time a datagram is sent, the local and receiving socket address need to be sent as well TCP (Transmission Control Protocol) • connection-oriented - provides a reliable flow of data between two computers _ data sent from one end of the connection gets to the other end in the same order • in order to communicate using TCP protocol, a connection must first be established between the pair of sockets • once two sockets have been connected, they can be used to transmit data in both (or either one of the) directions UDP vs. TCP: Which Protocol to Use? • Overhead _ UDP - every time a datagram is sent, the local and receiving socket address need to be sent along with it _ TCP - a connection must be established before communications between the pair of sockets start (i.e. there is a connection setup time in TCP) • Packet Size _ UDP - there is a size limit of 64 kilobytes per datagram _ TCP - there is no limit; the pair of...

Words: 2326 - Pages: 10

Free Essay

Chee

...Task 1 2. The LGA 1156 connector is also called the H or H1 socket. It connects the motherboard to the CPU, or central processing unit. Without this connection, the computer will not function. Intel core i3 uses lga 1156. And i7 and i7 extreme (intel) 3. Intel® Core™ i7-800, Intel® Core™ i5, and Intel® Core™ i3 processors. Its purpose on the motherboard is it determines the type of processor the motherboard accepts, the type of capacity of RAM, and what sort of internal & external devices the motherboard supports. It serves as an electronic interface through which the CPU, RAM and I/O devices interact. 4. Unique On/Off Charge delivers the best recharging capability to iPad, iPhone and iPod Touch, 3x USB power delivery for greater compatibility and extra power for USB devices, Leading quality standard of Ultra Durable™ 3 classic technology with 2oz copper PCB design, Innovative Smart 6 technology for smarter PC management, Supports Intel Core™ i7/ Core™ i5/ Core™ i3 LGA1156 processors Task 2 2. The purpose of the 770 Northbridge chipset on the motherboard is to link the computer system's hardware to the processor. It’s used with Phenom II processors, as well as Athlon II and Sempron 100 series processors. 3. The purpose of the motherboard for the AMD SB710 Southbrdge chipset is to control the processes that are going on within the computer's main frame system. Processors used with are: Socket AM3/AM2 Processors, AMD Turion™ II Neo | AMD Athlon™ II Neo Processors (ASB2) ...

Words: 477 - Pages: 2

Free Essay

Data

...C H A P T E R 5 AppleTalk Data Stream Protocol (ADSP) 5 This chapter describes the AppleTalk Data Stream Protocol (ADSP) that you use to establish a session to exchange data between two network processes or applications in which both parties have equal control over the communication. You should read this chapter if you want to write an application that supports the exchange of more than a small amount of data between two parties who each can both send and receive streams of data. This chapter also describes the AppleTalk Secure Data Stream Protocol (ASDSP), a secure version of ADSP, that allows users of your application to communicate over an ADSP session after the users’ identities have been authenticated. Users can then exchange encrypted data over the session. For your application to use ASDSP, the system on which it runs must have the AppleTalk Open Collaboration Environment (AOCE) software installed and must have access to an AOCE server. To use ASDSP, you must also use the Authentication Manager, which is a component of the AOCE software. For information on the Authentication Manager, refer to Inside Macintosh: AOCE Application Programming Interfaces. ASDSP enhances ADSP with authentication and encryption features. When this chapter discusses components of ADSP, such as connection ends and connection listeners, you can assume that the information also applies to ASDSP. The sections in this chapter that discuss ASDSP describe any specific differences between it...

Words: 29341 - Pages: 118

Free Essay

Fuel Filter Removal

...* What Tools May/Will I Need? * (2) 19mm Combination Wrenches (3/4" will also work) *Note* The open end on some wrenches may be too thick to fit around the neck of the fuel filter - my Craftsman wrenches were like this. I used another 19mm wrench (no-name brand) that was thinner for this job. * (1) 14mm Flare-nut Wrench [optional] * (1) 12mm Wrench or Socket (3/8" Drive) * (1) 10mm Wrench or Socket (1/4" or 3/8" Drive) * (1) 8mm Wrench or Socket (1/4" or 3/8" Drive) * (1) 3/8" Drive 6" [or longer] Extension * (1) 3/8" Drive Socket Wrench (or Air Ratchet) * (1) 1/4" Socket Wrench (or Air Ratchet) [optional] * (1) Phillps #2 Screwdriver * Shop Towels * Safety Goggles * Latex Gloves The 3000GT Fuel Filter | Your mission, should you choose to accept it, is to locate the elusive 3000GT/Stealth fuel filter (right), disconnect and remove it from the vehicle, and install a replacement filter. You should not be particularly fond of the skin on your knuckles, as you will most likely lose some of it. | The fuel filter, when disassembled, looks like the picture on the right. Note that the parts you will be turning to remove the fuel lines are the gold-colored bolts, NOT the neck (black) of the fuel filter itself | The Procedure | Remove the Spare Tire |   | Unscrew the bolt that holds it in the center. |   | | Remove the Passenger Side Cargo Tray |   | |   | There are three...

Words: 1872 - Pages: 8

Free Essay

Ntt1110

...3. That the Gigabyte GA-H55M-UD2H motherboard support the Intel H55 Chipset, the gamer aspect putting for the first time ever of integrated graphic on a chip. Which is allow to a new standard of high definition contents payback. Task 2: 1. 2. AMD 770 Northbridge Chipset purpose is to processor and the rest of the computer. The purpose for the AMD770 Northbridge Chipset on the motherboard is to link the processor and the rest of the computer to compaction 3. The purpose of the AMD SB710 Southbridge Chipset is to do power saving and video decoder, it uses AMD Turion, AMD Athlon, and AMD Sempron processors. The motherboard helps make control all the processor that goes on the main frame system within the computer. 4. The Socket AM3 Connector is connect to the AM3 and the AM3+ processor. Tasks 3: Examine Intel Processor Processor | Clock Speed | Internal Cache | Bus Speed | Architecture | I7 | 3.33MHz | 1.5MB | 4.8 GT/s | Bloomfield | I7 mobile | 1.5 GHz | 6MB | 2.5 GT/s | Clarksfield | I5 | 3.46 GHz | 8MB | 4.8 GT/s | Lynnfield | I5 mobile | 2.4GHz | 3MB | 2.5GT/s | Arrandale | I3 | 2.93GHz | 4 MB | 2.5GT/s | Clarkdale | I3 mobile | 2.13GHz | 3MB | 2.5GT/s | Nehalem | vPro | 2.9GHz | 3MB | 2.5GT/s | Clarksfild | vPro mobile | 3.40GHz | 4MB | 5GT/s | Nehalem | Xeon 7000 | 1.73 GHz | 4MB | 4GT/s | Nehalem | Xeon 5000 | 1.87GHz | 4MB | 2GT/s | Gainestown | Xeon 3000 | 2GHz | 4MB | DMI | Clardale |...

Words: 400 - Pages: 2

Premium Essay

Lab 4: Identify Motherboard Components and Form Factors

...Lab 4: Identify Motherboard Components and Form Factors Task 1: Procedure 2. Using Internet Explorer, locate information on the LGA 1156 connector. What processors is it used with? What is its purpose on the motherboard? Socket 1156, or LGA1156, also known as socket H1, is a Land Grid Array socket used by the first generation of workstation-class Intel Core i3, Core i5, Core i7, as well as Xeon 300 series microprocessors. The socket supports dual-channel DDR3 SDRAM memory controller, Direct Media Interface running at 2.5 GT/s, and PCI Express interface. The socket H1 works with processors with frequencies from 1.86 GHz to 3.46 GHz. It is supported by Intel® DMI Interconnect and integrated with the Dual-channel memory controller with 4 DIMM slots DDR3 memory. It supports the Intel Turbo boost technology and smart cache. http://www.cpu-world.com/Sockets/Socket%201156%20(LGA1156).html http://www.biostar-usa.com/app/en-us/mb/introduction.php?S_ID=473#ov 3. Using Internet Explorer, locate information on the Intel H55 Chipset. What processors is it used with? What is its purpose on the motherboard? The Intel H55 Chipset includes the FDI (Flexible Display Interface) which enables direct connection between the CPU and the graphics core. This allows the display information to be sent back to the H55 chipset for output. The graphics core inside the Clarkdale processor is known as GMA HD. Its difference from the G45 GMA X4500HD is in the number of Unified shaders which was increased...

Words: 1058 - Pages: 5

Premium Essay

Instruction Manual

...INTRODUCTION Computers continue to become more a part of everyday life. According to the census conducted in 2013, 86% of households in the U.S. had at least one computer, and it is likely that number has gone up in the last two years. Many families have more than one computer in the household. The cost of a computer can range from a couple hundred dollars to a couple thousand depending on the criteria the customer gives for the specifications of the computer. In computers there are three main options, first of which is to buy a branded computer, such as apple. The second option is to have a custom computer build by a company, such as ibuypower.com. The third option is to build your own computer with your own specifications. As far as cost goes, usually buying a branded computer is the cheapest option, and building a computer is slightly less costly than having a custom computer built. If a consumer is not saving money building their own computer, then why would you go through the hassle? There are many advantages to building you own computer, first amongst them is the consumer gets exactly what they want. Building your own computer allows flexibility that isn’t there otherwise. The consumer can adjust the parts to fit a specific budget and can build the computer with a specific goal in mind, such as a high-end gaming computer, or a family multimedia computer. When buying from a company, you get exactly what they make, there are not many variations or customizations in...

Words: 2070 - Pages: 9