Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Network-Chat:


Compiler Delphi Multi
Components None
Discription Network Chat
Last Update 012026
License Freeware


Online chat is any direct text-, audio- or video-based , one-on-one or one-to-many (group) chat (formally also known as synchronous conferencing), using tools such as instant messengers, Internet Relay Chat (IRC), talkers and possibly MUDs or other online games. Online chat includes web-based applications that allow communication – often directly addressed, but anonymous between users in a multi-user environment. Web conferencing is a more specific online service, that is often sold as a service, hosted on a web server controlled by the vendor. Online chat may address point-to-point communications as well as multicast communications from one sender to multiple receivers and voice and video chat, or may be a feature of a web conferencing service.


NetworkChat


Online chat in a narrower sense is any kind of communication over the Internet that offers a real-time transmission of text messages from sender to receiver. Chat messages are generally short in order to enable other participants to respond quickly. Thereby, a feeling similar to a spoken conversation is created, which distinguishes chatting from other text-based online communication forms such as Internet forums and email. The expression online chat comes from the word chat which means "informal conversation".


Connection:

network socket is a software structure within a network node of a computer network that serves as an endpoint for sending and receiving data across the network. The structure and properties of a socket are defined by an application programming interface (API) for the networking architecture. Sockets are created only during the lifetime of a process of an application running in the node.

Because of the standardization of the TCP/IP protocols in the development of the Internet, the term network socket is most commonly used in the context of the Internet protocol suite, and is therefore often also referred to as Internet socket. In this context, a socket is externally identified to other hosts by its socket address, which is the triad of transport protocol, IP address, and port number.

The term socket is also used for the software endpoint of node-internal inter-process communication (IPC), which often uses the same API as a network socket.


Socket addresses:

An application can communicate with a remote process by exchanging data with TCP/IP by knowing the combination of protocol type, IP address, and port number. This combination is often known as a socket address. It is the network-facing access handle to the network socket. The remote process establishes a network socket in its own instance of the protocol stack and uses the networking API to connect to the application, presenting its own socket address for use by the application.


Examples:

This example in Java, modeled according to the Berkeley socket interface, sends the string "Hello, world!" via TCP to port 80 of the host with address 203.0.113.0. It illustrates the creation of a socket, connecting it to the remote host, sending the string, and finally closing the socket:

Java Example:


package org.wikipedia.examples;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;

public class Main {
    public static void main(String[] args) {
        InetAddress address = InetAddress.getByName("203.0.113.0");

        // IP = 203.0.113.0, port = 80
        // the Socket is automatically closed at the end of the try block
        // java.net.Socket uses TCP, while java.net.DatagramSocket uses UDP
        try (Socket socket = new Socket(address, 80)) {
            // writes to the output stream of the socket, with automatic flushing enabled
            PrintWriter socketOut = new PrintWriter(socket.getOutputStream(), true);
            socketOut.println("Hello, world!");
        } catch (SocketException e) {
            System.out.printf("An error occurred while accessing the socket: %s%n", e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            System.out.printf("An error occurred while writing to socket: %s%n", e.getMessage());
            e.printStackTrace();
        }
    }
}

The traditional Berkeley sockets usage in C would look like this:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <arpa/inet.h>
#include <unistd.h>

int main() {
    char message[] = "Hello, World!";

    // Create socket
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1) {
        fprintf(stderr, "Failed to create socket!\n");
        return 1;
    }

    // Set server address
    struct sockaddr_in server_addr = {
        .sin_family = AF_INET, // Address family
        .sin_port = htons(80), // Port number (converted to network byte order)
        .sin_addr.s_addr = inet_addr("203.0.113.0"), // IP address
    };

    // Connect to server
    if (connect(sockfd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == -1) {
        fprintf(stderr, "Connection failed!\n");
        return 1;
    }

    // Send message
    send(sockfd, message, strlen(message), 0);
    printf("Message sent!\n");

    // Close socket
    close(sockfd);
    return 0;
}

Simple code to send and receive data by TCP in Python:


#!/usr/bin/env python

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 5005
BUFFER_SIZE = 1024
MESSAGE = "Hello, World!"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()

print "received data:", data

Simple code to serve TCP in Python:


#!/usr/bin/env python

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 5005
BUFFER_SIZE = 20  # Normally 1024, but we want fast response

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

conn, addr = s.accept()
print 'Connection address:', addr
while 1:
  data = conn.recv(BUFFER_SIZE)
  if not data: break
  print "received data:", data
  conn.send(data)  # echo
  conn.close()

Protocols:

The following list are common chat programs and protocols.

Chat programs supporting multiple protocols:

About

This is a fully-fledged example of a network chat program with several features.

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages