Winsock Control. TCP Basics

Similar documents
VB Socket Visual Basic socket implementation

Return Codes and Associated Messages

Data Acquisition over Ethernet using Serial Device Server - NPort 5210 PRL-TN

Inspirel. YAMI4 Requirements. For YAMI4Industry, v page 1

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

escl* Communication Reference Guide

Context. Distributed Systems: Sockets Programming. Alberto Bosio, Associate Professor UM Microelectronic Departement

Appendix. Web Command Error Codes. Web Command Error Codes

Transport Layer. Gursharan Singh Tatla. Upendra Sharma. 1

SOCKET. Valerio Di Valerio

GIVE W INGS TO YOUR IDEAS

A set of processes distributed over a network that communicate via messages. Processes communicate via services offered by the operating system

Socket Programming for TCP and UDP

Interprocess Communication

Error num: 1 Meaning: Not owner Error num: 2 Meaning: No such file or directory Error num: 3 Meaning: No such process Error num: 4 Meaning:

Chapter 2 Applications and

Sockets 15H2. Inshik Song

Opto 22 Ethernet Driver Help Kepware Technologies

Programming Assignment 1

Networking Technologies and Applications

Group-A Assignment No. 6

SOCKETLIB. Requirements

Introduction to Computer Systems. Networks 2. c Theodore Norvell. The Sockets API

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-9: WCE Serial Communication, Network, device-to

Programming Assignment 1

Socket Programming. Sungkyunkwan University. Hyunseung Choo Copyright Networking Laboratory

Configuring CSM Scripts

Distributed Systems Recitation 2. Tamim Jabban

TRANSMISSION CONTROL PROTOCOL. ETI 2506 TELECOMMUNICATION SYSTEMS Monday, 7 November 2016

Outline. Option Types. Socket Options SWE 545. Socket Options. Out-of-Band Data. Advanced Socket. Many socket options are Boolean flags

Distributed Systems Recitation 2. Tamim Jabban

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 4 (document version 1.0) Network Programming using C

The TCP/IP UNAPI specification

Kea Messages Manual. Kea Messages Manual

Interprocess Communication

Erlangen API Documentation

T27 express Connect 8 May 2008

External Data Representation (XDR)

Network Programming. Introduction to Sockets. Dr. Thaier Hayajneh. Process Layer. Network Layer. Berkeley API

Introduction to Network. Topics

User Datagram Protocol(UDP)

Lecture 5 Overview! Last Lecture! This Lecture! Next Lecture! I/O multiplexing! Source: Chapter 6 of Stevens book!

STUDY OF SOCKET PROGRAMMING

ESPSX3 Ethernet Serial Port Server X 3 Users Guide

Ports under 1024 are often considered special, and usually require special OS privileges to use.

COMPUTER NETWORK. Homework #2. Due Date: April 12, 2017 in class

Chapter 6. What happens at the Transport Layer? Services provided Transport protocols UDP TCP Flow control Congestion control

Command Manual (For Soliton) IP Address-IP Performance. Table of Contents

Introduction to Computer Networks

JAVA SOCKET PROGRAMMING

ESPSX3 Ethernet Serial Port Server X 3

UNIT IV- SOCKETS Part A

Catalyst Development Corporation An Introduction to TCP/IP Programming With SocketWrench

NETWORK PROGRAMMING AND MANAGEMENT 1 KINGS DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK

UDP CONNECT TO A SERVER

T01F3nnn - FTP3 Messages

Network Programming in Python. based on Chun, chapter 2; plus material on classes

Lecture 2. Outline. Layering and Protocols. Network Architecture. Layering and Protocols. Layering and Protocols. Chapter 1 - Foundation

DNP Master Ethernet Driver Help Kepware Technologies

Overview. Exercise 0: Implementing a Client. Setup and Preparation

Bringing together EagleEyes users: Creating TCP Peer-to-Peer programs for two person interaction over the internet

B. Including the Event Structure within a loop. C. Configuring a Timeout case within the Event Structure

Chapter 5 End-to-End Protocols

Table of Contents 1 IP Address Configuration Commands IP Performance Configuration Commands 2-1

Socket Security: Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE

05 Transmission Control Protocol (TCP)

Overview. Exercise 0: Implementing a Client. Setup and Preparation

Presentation Services. Presentation Services: Motivation

Transport Layer. The transport layer is responsible for the delivery of a message from one process to another. RSManiaol

UNIX Sockets. COS 461 Precept 1

The User Datagram Protocol

Tutorial on Socket Programming

ELEC / COMP 177 Fall Some slides from Kurose and Ross, Computer Networking, 5 th Edition

Java Support for developing TCP Network Based Programs

EECS122 Communications Networks Socket Programming. Jörn Altmann

Computer Network Lab, SS Fachgebiet Technische Informatik, Joachim Zumbrägel. Overview. Sockets. Sockets in C.

Elementary TCP Sockets

Implementing Secure Shell

Table of Contents 1 IP Address Configuration Commands IP Performance Configuration Commands 2-1

Configuring attack detection and prevention 1

ACE Connection Interface Specification Version 0.9

Transport Layer. Application / Transport Interface. Transport Layer Services. Transport Layer Connections

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

Networked Applications: Sockets. Goals of Todayʼs Lecture. End System: Computer on the ʻNet. Client-server paradigm End systems Clients and servers

A few years ago, I was called in to a hectic call-centre the head honcho had a problem.

IEMS 5780 / IERG 4080 Building and Deploying Scalable Machine Learning Services

ECE 650 Systems Programming & Engineering. Spring 2018

Kea Messages Manual. Kea Messages Manual

The TCPProxy. Table of contents

Introduction to Client-Server Model

CSE 461 Connections. David Wetherall

Chapter 11. Application-Layer Elements Ports

Transport Layer (TCP/UDP)

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

(Refer Slide Time: 1:09)

sottotitolo Socket Programming Milano, XX mese 20XX A.A. 2016/17 Federico Reghenzani

Lecture 3: The Transport Layer: UDP and TCP

Distributed Internet Applications - DIA. Servers and Sockets

Distributed Real-Time Control Systems. Module 26 Sockets

Transcription:

Winsock Control Winsock Control The Winsock control, invisible to the user, provides easy access to TCP and UDP network services. It can be used by Microsoft Access, Visual Basic, Visual C++, or Visual FoxPro developers. To write client or server applications you do not need to understand the details of TCP or to call low level Winsock APIs. By setting properties and invoking methods of the control, you can easily connect to a remote machine and exchange data in both directions. TCP Basics The Transfer Control Protocol allows you to create and maintain a connection to a remote computer. Using the connection, both computers can stream data between themselves. If you are creating a client application, you must know the server computer's name or IP address (RemoteHost property), as well as the port (RemotePort property) on which it will be "listening." Then invoke the Connect method. If you are creating a server application, set a port (LocalPort property) on which to listen, and invoke the Listen method. When the client computer requests a connection, the ConnectionRequest event will occur. To complete the connection, invoke the Accept method within the ConnectionRequest event. Once a connection has been made, either computer can send and receive data. To send data, invoke the SendData method. Whenever data is received, the DataArrival event occurs. Invoke the GetData method within the DataArrival event to retrieve the data. UDP Basics The User Datagram Protocol (UDP) is a connectionless protocol. Unlike TCP operations, computers do not establish a connection. Also, a UDP application can be either a client or a server. To transmit data, first set the client computer's LocalPort property. The server computer then needs only to set the RemoteHost to the Internet address of the client computer, and the RemotePort property to the same port as the client computer's LocalPort property, and invoke the SendData method to begin sending messages. The client computer then uses the GetData method within the DataArrival event to retrieve the sent messages.

RemoteHostIP Property RemoteHostIP Property Returns the IP address of the remote machine. For client applications, after a connection has been established using the Connect method, this property contains the IP string of the remote machine. For server applications, after an incoming connection request (ConnectionRequest event), this property contains the IP string of the remote machine that initiated the connection. When using the UDP protocol, after the DataArrival event occurs, this property contains the IP address of the machine sending the UDP data. object.remotehostip The object placeholder represents an object expression that evaluates to an object in the Applies To list. Data Type String

Protocol Property (Winsock Control) Protocol Property (Winsock Control) Returns or sets the protocol, either TCP or UDP, used by the Winsock control. object.protocol [=protocol] The object placeholder represents an object expression that evaluates to an object in the Applies To list. Settings The settings for protocol are: Constant Value Description scktcpprotocol 0 Default. TCP protocol. sckudpprotocol 1 UDP protocol. Return Value Void The control must be closed (using the Close method) before this property can be reset.

State Property (Winsock Control) State Property (Winsock Control) Returns the state of the control, expressed as an enumerated type. Read-only and unavailable at design time. object.state The object placeholder represents an object expression that evaluates to an object in the Applies To list. Data Type Integer Settings The settings for the State property are: Constant Value Description sckclosed 0 Default. Closed sckopen 1 Open scklistening 2 Listening sckconnectionpending 3 Connection pending sckresolvinghost 4 Resolving host sckhostresolved 5 Host resolved sckconnecting 6 Connecting sckconnected 7 Connected sckclosing 8 Peer is closing the connection sckerror 9 Error

Accept Method Accept Method For TCP server applications only. This method is used to accept an incoming connection when handling a ConnectionRequest event. object.accept requestid The object placeholder represents an object expression that evaluates to an object in the Applies To list. Data Type Long Return Value Void The Accept method is used in the ConnectionRequest event. The ConnectionRequest event has a corresponding argument, the RequestID parameter, that should be passed to the Accept method. An example is shown below: Private Sub Winsock1_ConnectionRequest _ (ByVal requestid As Long) ' Close the connection if it is currently open ' by testing the State property. If Winsock1.State <> sckclosed Then Winsock1.Close ' Pass the value of the requestid parameter to the ' Accept method. Winsock1.Accept requestid End Sub The Accept method should be used on a new control instance (other than the one that is in the listening state.)

Bind Method Bind Method Specifies the LocalPort and LocalIP to be used for TCP connections. Use this method if you have multiple protocol adapters. object.bind LocalPort, LocalIP The Bind method syntax has these parts Part object LocalPort LocalIP Description An object expression that evaluates to an object in the Applies To list. The port used to make a connection. The local Internet address used to make a connection. You must invoke the Bind method before invoking the Listen method.

Close Method (Winsock Control) Close Method (Winsock Control) Closes a TCP connection or a listening socket for both client and server applications. object.close The object placeholder represents an object expression that evaluates to an object in the Applies To list. Arguments None Return Value Void

Listen Method Listen Method Creates a socket and sets it in listen mode. This method works only for TCP connections. object.listen The object placeholder represents an object expression that evaluates to an object in the Applies To list. Arguments None Return Value Void The ConnectionRequest event occurs when there is an incoming connection. When handling ConnectionRequest, the application should use the Accept method (on a new control instance) to accept the connection.

SendData Method SendData Method Sends data to a remote computer. Return Value Void object.senddata data The SendData method syntax has these parts Part object data Description An object expression that evaluates to an object in the Applies To list. Data to be sent. For binary data, byte array should be used. When a UNICODE string is passed in, it is converted to an ANSI string before being sent out on the network.

Close Event Close Event Occurs when the remote computer closes the connection. Applications should use the Close method to correctly close a TCP connection. object_close( ) The object placeholder represents an object expression that evaluates to an object in the Applies To list. Arguments None

Connect Event (Winsock Control) Connect Event (Winsock Control) Occurs when a Connect operation is completed. object.connect() The object placeholder represents an object expression that evaluates to a Winsock control. Use the Connect event to confirm when a connection has been made successfully.

ConnectionRequest Event ConnectionRequest Event Occurs when a remote machine requests a connection. For TCP server applications only. The event is activated when there is an incoming connection request. RemoteHostIP and RemotePort properties store the information about the client after the event is activated. object_connectionrequest (requestid As Long) The ConnectionRequest event syntax has these parts: Part object requestid Description An object expression that evaluates to an object in the Applies To list. The incoming connection request identifier. This argument should be passed to the Accept method on the second control instance. The server can decide whether or not to accept the connection. If the incoming connection is not accepted, the peer (client) will get the Close event. Use the Accept method (on a new control instance) to accept an incoming connection.

DataArrival Event DataArrival Event Occurs when new data arrives. object_dataarrival (bytestotal As Long) The DataArrival event syntax has these parts: Part object bytestotal Description An object expression that evaluates to an object in the Applies To list. Long. The total amount of data that can be retrieved. This event will not occur if you do not retrieve all the data in one GetData call. It is activated only when there is new data. Use the BytesReceived property to check how much data is available at any time.

Error Event (Winsock Control) Page 1 of 2 Error Event (Winsock Control) Occurs whenever an error occurs in background processing (for example, failed to connect, or failed to send or receive in the background). object_error(number As Integer, Description As String, Scode As Long, Source As String, HelpFile as String, HelpContext As Long, CancelDisplay As Boolean) The Error event syntax has these parts: Part object number description Scode Source HelpFile HelpContext CancelDisplay Description An object expression that evaluates to an object in the Applies To list. An integer that defines the error code. See Settings below for constants. String containing error information. The long SCODE String describing the error source. String containing the help file name. Help file context. Indicates whether to cancel the display. The default is False, which is to display the default error message box. If you do not want to use the default message box, set CancelDisplay to True. Settings The settings for number are: Constant Value Description sckoutofmemory 7 Out of memory sckinvalidpropertyvalue 380 The property value is invalid. sckgetnotsupported 394 The property can't be read. scksetnotsupported 383 The property is read-only. sckbadstate 40006 Wrong protocol or connection state for the requested transaction or request. sckinvalidarg 40014 The argument passed to a function was not in the correct format or in the specified range. scksuccess 40017 Successful. sckunsupported 40018 Unsupported variant type. sckinvalidop 40020 Invalid operation at current state sckoutofrange 40021 Argument is out of range. sckwrongprotocol 40026 Wrong protocol for the requested transaction or request

Error Event (Winsock Control) Page 2 of 2 sckopcanceled 1004 The operation was canceled. sckinvalidargument 10014 The requested address is a broadcast address, but flag is not set. sckwouldblock 10035 Socket is non-blocking and the specified operation will block. sckinprogress 10036 A blocking Winsock operation in progress. sckalreadycomplete 10037 The operation is completed. No blocking operation in progress scknotsocket 10038 The descriptor is not a socket. sckmsgtoobig 10040 The datagram is too large to fit into the buffer and is truncated. sckportnotsupported 10043 The specified port is not supported. sckaddressinuse 10048 Address in use. sckaddressnotavailable 10049 Address not available from the local machine. scknetworksubsystemfailed 10050 Network subsystem failed. scknetworkunreachable 10051 The network cannot be reached from this host at this time. scknetreset 10052 Connection has timed out when SO_KEEPALIVE is set. sckconnectaborted 11053 Connection is aborted due to timeout or other failure. sckconnectionreset 10054 The connection is reset by remote side. scknobufferspace 10055 No buffer space is available. sckalreadyconnected 10056 Socket is already connected. scknotconnected 10057 Socket is not connected. scksocketshutdown 10058 Socket has been shut down. scktimedout 10060 Socket has been shut down. sckconnectionrefused 10061 Connection is forcefully rejected. scknotinitialized 10093 WinsockInit should be called first. sckhostnotfound 11001 Authoritative answer: Host not found. sckhostnotfoundtryagain 11002 Non-Authoritative answer: Host not found. scknonrecoverableerror 11003 Non-recoverable errors. scknodata 11004 Valid name, no data record of requested type.