Library tutorials & articles
Introduction to TCP/IP
- Introduction
- Transmission Control Protocol (TCP)
- User Datagram Protocol
- Hostnames
- Service Ports
- Sockets
- Client-Server Protocol
- Blocking vs. Non-Blocking Sockets
Transmission Control Protocol (TCP)
When two computers wish to exchange information over a network, there are several components that must be in place before the data can actually be sent and received. Of course, the physical hardware must exist, which is typically either a network interface card (NIC) or a serial communications port for dial-up networking connections. Beyond this physical connection, however, computers also need to use a protocol which defines the parameters of the communication between them. In short, a protocol defines the "rules of the road" that each computer must follow so that all of the systems in the network can exchange data. One of the most popular protocols in use today is TCP/IP, which stands for Transmission Control Protocol/Internet Protocol.
By convention, TCP/IP is used to refer to a suite of protocols, all based on the Internet Protocol (IP). Unlike a single local network, where every system is directly connected to each other, an internet is a collection of networks, combined into a single, virtual network. The Internet Protocol provides the means by which any system on any network can communicate with another as easily as if they were on the same physical network. Each system, commonly referred to as a host, is assigned a unique 32-bit number which can be used to identify it over the network. Typically, this address is broken into four 8-bit numbers separated by periods. This is called dot-notation, and looks something like "192.43.19.64". Some parts of the address are used to identify the network that the system is connected to, and the remainder identifies the system itself. Without going into the minutia of the Internet addressing scheme, just be aware that there are three "classes" of addresses, referred to as "A", "B" and "C". The rule of thumb is that class "A" addresses are assigned to very large networks, class "B" addresses are assigned to medium sized networks, and class "C" addresses are assigned to smaller networks (networks with less than approximately 250 hosts).
When a system sends data over the network using the Internet Protocol, it is sent in discrete units called datagrams, also commonly referred to as packets. A datagram consists of a header followed by application-defined data. The header contains the addressing information which is used to deliver the datagram to it's destination, much like an envelope is used to address and contain postal mail. And like postal mail, there is no guarantee that a datagram will actually arrive at it's destination. In fact, datagrams may be lost, duplicated or delivered out of order during their travels over the network. Needless to say, this kind of unreliability can cause a lot of problems for software developers. What's really needed is a reliable, straight-forward way to exchange data without having to worry about lost packets or jumbled data.
To fill this need, the Transmission Control Protocol (TCP) was developed. Built on top of IP, TCP offers a reliable, full-duplex byte stream which may be read and written to in a fashion similar to reading and writing a file. The advantages to this are obvious: the application programmer doesn't need to write code to handle dropped or out-of-order datagrams, and instead can focus on the application itself. And because the data is presented as a stream of bytes, existing code can be easily adopted and modified to use TCP.
TCP is known as a connection-oriented protocol. In other words, before two programs can begin to exchange data they must establish a "connection" with each other. This is done with a three-way handshake in which both sides exchange packets and establish the initial packet sequence numbers (the sequence number is important because, as mentioned above, datagrams can arrive out of order; this number is used to ensure that data is received in the order that it was sent). When establishing a connection, one program must assume the role of the client, and the other the server. The client is responsible for initiating the connection, while the server's responsibility is to wait, listen and respond to incoming connections. Once the connection has been established, both sides may send and receive data until the connection is closed.
Related articles
Related podcasts
-
Scott talks to Martin Fowler and David Heinemeier Hansson
Scott sits down with Martin Fowler of Thoughtworks and David Heinemeier Hansson of 37 signals and talks about beauty, making developers happen, the death (or life) of HTML, the future of Microsoft, and asks if we should care about Rich Internet Applications. DHH is the creator of the Ruby on Rail...
Events coming up
-
Dec
2
Web Standards Group (Sydney)
North Sydney, Australia
TBA
hi
This is possible using threads in the client program. the client can generate parallel connections using threads. so u can create multiple clients in the same system.
In the server side, you use two sockets. One for receive the data and another for response to corresponding clients. Use the FDSET, FDISSET functions to achieve this apps. This is reliable one
Hope I may answered your question.
Karthik
hi i want to make socket connection for the multiple clients like i want to send the data to the server to the multiple clients how i will be able to do that. IS there anybody else who can help me. I am able to do that by socket programming but only in single system when i want to do that on multiple system then it is not possible.is there any one? its very needed.................................... thanks and bye
Hi,
Iam developing the socket application.In this the remote host is sending messages.But iam not able to pick all the messages sent by the remote host.If remote is sending 10 msgs,then iam able to pick 2 or 3 msgs.pls tell me,what could be the reason for that asap.
Thank you.
i m sending this code asuming that u have some prior knowledge about network programming
include this code at server side
Private Sub listen_Click()
Winsock1.LocalPort = 1002
Winsock1.listen
End Sub
Private Sub cmdsend_Click()
Winsock1.SendData chattxtbox.Text
txtwindow.Text = txtwindow.Text & vbNewLine & chattxtbox.Text
chattxtbox.Text = ""
txtwindow.SelStart = Len(txtwindow)
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim txtwindowdata As String
Winsock1.GetData txtwindowdata
txtwindow.Text = txtwindow.Text & vbNewLine & txtwindowdata
txtwindow.SelStart = Len(txtwindow)
End Sub
//include this one at client siderivate Sub cmdconnect_Click()
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 1002
Winsock1.Connect
End Sub
Private Sub cmdsend_Click()
Winsock1.SendData chattxtbox.Text
rectxtwindow.Text = rectxtwindow.Text & vbNewLine & rectxtwindow.Text
chattxtbox.Text = ""
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim txtfromserver As String
Winsock1.GetData txtfromserver
rectxtwindow.Text = rectxtwindow.Text & vbNewLine & txtfromserver
rectxtwindow.SelStart = Len(rectxtwindow)
End Sub
Private Sub Winsock1_Connect()
MsgBox "Connecting to Server....Plz stay far n WAIT"
End Sub
this will make a client server chat applicatin with in a LAN
Hi. I read ur message. I'm doing a (socket programming) chatty client/server messenger program too and I need lots of help. I heard you have done it. Could u send me ur source code and i could refer to it. Thanks alot it will help me greatly. By the way i'm using tcp.
example:
for each.. blah blah
Winsock1.SendData blah
DoEvents
end for
Hi...
im new to tcp programming using winsock control in Vusual Basic.
i tried a client server chat program, in which there is a client program running and its
communicting with a server program. when i tried with two clients communicating thru a server program..its not working...can you help me....please send the source code also..
By
Faisal
I only speak a lite bit of English
I need to know the name of the file on Windows to define a
new LocalPort (UDP port) for a new application (Client/Server) of
Files.
Mi lenguaje es el Castellano.
Thanks Javier
If you're using SocketWrench, there's an HTTP client and server example that's included that could probably serve as a foundation for what you're interested in doing. If you have any specific questions, I'd be happy to answer them for you.
I am a new member and my question might have been asked before but i can not find it in the archives.
But if anyone would be able to help, please do. I would be greatful.
Q: I have to create a (http like) protocol to enable the client communicate with a server. I know the basics but would be greatful for any ideas. Thanks
How are you broadcasting? Are you using TCP/IP or UDP? I have sent broadcast messages using UDP just by using the broadcast address 255.255.255.255 so that the packet goes everywhere. I had problems prior to using this when the PC's were in different domains. I dont know if this helps!
i created a client/server application using winsock, and everything works fine except if i try to send a message to all the clients from the server, only the last client actually recieves the message. after much research i found the service pack 4 for VB resolves this issue...but it only resolved the issue if i use my computer (that has VB) as the server.... i need to use a computer that does not have VB to be the server. Can anyone help me!!!!!
This thread is for discussions of Introduction to TCP/IP.