09-16-2003
Let's say that you have two computers connected by a network....let's call them Jenn and Ben. They both will have IP addresses: Jenn=192.168.30.1 and Ben=192.168.30.2
Let's say that you are on Jenn and you want to telnet to Ben. From Jenn, you can send packets to Ben by addressing them to 192.168.30.2. But how will Ben know what to do with them when they arrive? This is where port numbers come in.
On Jenn, you would run the telnet command. It will need a local port number and it just pick one. This kind of port is a high number...let's say it picks 5,327. It also looks up it's local IP address which is 192.168.30.1. This pair of numbers (192.168.30.1 and 5,327) will be one endpoint of the connection.
Now it looks up Ben's address which is 192.168.30.2. It knows that it wants to talk to a telnet server on Ben. By convention, a telnet server must use port 23. 23 is a well known port...these are low numbers.
Now the telnet program will establish a connection from (192.168.30.1 and 5,327) to (192.168.30.2 and 23). You need all 4 numbers to identify a connection.
Originally, the pair of numbers (ip address and port) were called a "socket". And it sometimes still is.
But in Unix, socket is also a system call that can be used to write network programs. A socket is also the data structure created by the socket() system. I have heard a few people speak in a way that suggests that they think that a socket is all 4 numbers in a connection. So it's hard to say exactly what a socket is.
10 More Discussions You Might Find Interesting
1. Programming
Hi !
I had a verry simple question to ask...
In unix when we create pipes.. the unnamed pipes that is...
is there any way to access those pipes outside the code ?
Another thing.. do sockets have an entry in the inode table ?
TIA,
Devyani. (1 Reply)
Discussion started by: devy8
1 Replies
2. Programming
I am looking for a way to have a program listen on a port (example: 8000) for communication I will be sending via that port to it(Linux Kernel machine). Once it recieves an appropiate command I need it to run a .bat file in linux.
I know what I need to do but I am running into a few problems:... (8 Replies)
Discussion started by: bigB8210
8 Replies
3. Programming
Hai,
How cani declare socket and collect the data in a string varialbe.
Since i am new to this i am asking this.
Can we connect multiple port.
Thank you. (6 Replies)
Discussion started by: arunkumar_mca
6 Replies
4. Solaris
Ok for clarification if I look at a netstat -a while an active
telnet session is taking place. I see two lines of telnet info
under the IPv4 heading. Whats the 2366 part of the remote
ip address?
TCP: IPv4
Local Address Remote Address Swind Send-Q Rwind Recv-Q State
... (2 Replies)
Discussion started by: bdsffl
2 Replies
5. Solaris
Is there a way to see what sockets are in use? The developers here are getting some defunct processes and they would like to get a socket list.
This is on a Solaris 8 machine.
Thanks! (1 Reply)
Discussion started by: kjbaumann
1 Replies
6. Programming
anyone and teach me how to save standard output to a file in a client/server socket. I know how to read them to the screen but i'm not quite sure how to save them to a file.
my read to screen file code:
memset(line, 0x0, LINE_ARRAY_SIZE);
while (recv(connectSocket, line, MAX_MSG, 0) >... (1 Reply)
Discussion started by: crunchyuser
1 Replies
7. Programming
Hi,i now moved into a different section where i need to use sockets.
i am completely nill in sockets.
can some body please provide me what are the requirements for a socket.
to use sockets in c.
thanks (1 Reply)
Discussion started by: MrUser
1 Replies
8. Programming
if i have a server which wants to connect to exactly 5 clients, does that mean i need 5 socket file descriptors and use
listen(socket_fd,1);
for each one
or just do
listen(socket_fd,5)
also whats the second parameter number mean? what happens if i put 0 there?
also if i am connected... (28 Replies)
Discussion started by: omega666
28 Replies
9. Red Hat
hai guys,
I'm doing a project in which one server communicates with several clients. How can i do it when i have different port numbers???:confused: (0 Replies)
Discussion started by: rajeshb6
0 Replies
10. Programming
Hi, i am student, think learning about c++, someone has a example the how establish a conection with sockets :b::b: (1 Reply)
Discussion started by: mmartinez
1 Replies
LEARN ABOUT DEBIAN
sockets.socketpair
Sockets.socketPair(3kaya) Kaya module reference Sockets.socketPair(3kaya)
NAME
Sockets::socketPair - Create a joined pair of sockets
SYNOPSIS
Pair<Socket, Socket> socketPair( )
DESCRIPTION
This function creates a pair of sockets that can be used for bi-directional communication. The most common use of this is for setting up
communications between a process and its Posix.fork(3kaya) ()ed child - each process closes one of the sockets after the fork.
sockets = socketPair();
pid = fork();
if (pid == 0) {
// child process
close(sockets.fst);
// do something
} else {
close(sockets.snd);
// do something else
}
AUTHORS
Kaya standard library by Edwin Brady, Chris Morris and others (kaya@kayalang.org). For further information see http://kayalang.org/
LICENSE
The Kaya standard library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
License (version 2.1 or any later version) as published by the Free Software Foundation.
RELATED
Sockets.Socket(3kaya)
Sockets.close(3kaya)
Posix.fork(3kaya)
Kaya October 2012 Sockets.socketPair(3kaya)