• Español – América Latina
  • Português – Brasil
  • Tiếng Việt
  • Platform Apps APIs

chrome.sockets.tcp

Description.

Use the chrome.sockets.tcp API to send and receive data over the network using TCP connections. This API supersedes the TCP functionality previously found in the chrome.socket API.

The following keys must be declared in the manifest to use this API.

The ID of the newly created socket. Note that socket IDs created from this API are not compatible with socket IDs created from other APIs, such as the deprecated [ socket ](../socket/) API.

DnsQueryType

DNS resolution preferences. The default is any and uses the current OS config which may return IPv4 or IPv6. ipv4 forces IPv4, and ipv6 forces IPv6.

"any"

"ipv4"

"ipv6"

ReceiveErrorInfo

The result code returned from the underlying network call.

The socket identifier.

ReceiveInfo

ArrayBuffer

The data received, with a maxium size of bufferSize .

SecureOptions

TLSVersionConstraints   optional

number  optional

The number of bytes sent (if result == 0)

The result code returned from the underlying network call. A negative value indicates an error.

The size of the buffer used to receive data. If no buffer size has been specified explictly, the value is not provided.

Flag indicating whether the socket is connected to a remote peer.

string  optional

If the underlying socket is connected, contains its local IPv4/6 address.

If the underlying socket is connected, contains its local port.

Application-defined string associated with the socket.

Flag indicating whether a connected socket blocks its peer from sending more data (see setPaused ).

If the underlying socket is connected, contains the peer/ IPv4/6 address.

If the underlying socket is connected, contains the peer port.

Flag indicating whether the socket is left open when the application is suspended (see SocketProperties.persistent ).

SocketProperties

The size of the buffer used to receive data. The default value is 4096.

An application-defined string associated with the socket.

boolean  optional

Flag indicating if the socket is left open when the event page of the application is unloaded (see Manage App Lifecycle ). The default value is "false." When the application is loaded, any sockets previously opened with persistent=true can be fetched with getSockets .

TLSVersionConstraints

The minimum and maximum acceptable versions of TLS. Supported values are tls1.2 or tls1.3 .

The values tls1 and tls1.1 are no longer supported. If min is set to one of these values, it will be silently clamped to tls1.2 . If max is set to one of those values, or any other unrecognized value, it will be silently ignored.

Closes the socket and releases the address/port the socket is bound to. Each socket created should be closed after use. The socket id is no no longer valid as soon at the function is called. However, the socket is guaranteed to be closed only when the callback is invoked.

function  optional

The callback parameter looks like: () =>   void

Promise<void>

Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

Connects the socket to a remote machine. When the connect operation completes successfully, onReceive events are raised when data is received from the peer. If a network error occurs while the runtime is receiving packets, a onReceiveError event is raised, at which point no more onReceive event will be raised for this socket until the resume method is called.

The address of the remote machine. DNS name, IPv4 and IPv6 formats are supported.

The port of the remote machine.

DnsQueryType   optional

The address resolution preference.

The callback parameter looks like: ( result :   number ) =>   void

Creates a TCP socket.

SocketProperties   optional

The socket properties (optional).

The callback parameter looks like: ( createInfo :   CreateInfo ) =>   void

The result of the socket creation.

Promise< CreateInfo >

disconnect()

Disconnects the socket.

Retrieves the state of the given socket.

The callback parameter looks like: ( socketInfo :   SocketInfo ) =>   void

Object containing the socket information.

Promise< SocketInfo >

getSockets()

Retrieves the list of currently opened sockets owned by the application.

The callback parameter looks like: ( socketInfos :   SocketInfo []) =>   void

SocketInfo []

Array of object containing socket information.

Promise< SocketInfo []>

Start a TLS client connection over the connected TCP client socket.

The existing, connected socket to use.

SecureOptions   optional

Constraints and parameters for the TLS connection.

Sends data on the given TCP socket.

The data to send.

The callback parameter looks like: ( sendInfo :   SendInfo ) =>   void

Result of the send method.

setKeepAlive()

Enables or disables the keep-alive functionality for a TCP connection.

If true, enable keep-alive functionality.

Set the delay seconds between the last data packet received and the first keepalive probe. Default is 0.

setNoDelay()

Sets or clears TCP_NODELAY for a TCP connection. Nagle's algorithm will be disabled when TCP_NODELAY is set.

If true, disables Nagle's algorithm.

setPaused()

Enables or disables the application from receiving messages from its peer. The default value is "false". Pausing a socket is typically used by an application to throttle data sent by its peer. When a socket is paused, no onReceive event is raised. When a socket is connected and un-paused, onReceive events are raised again when messages are received.

Updates the socket properties.

The properties to update.

Event raised when data has been received for a given socket.

The callback parameter looks like: ( info :   ReceiveInfo ) =>   void

onReceiveError

Event raised when a network error occured while the runtime was waiting for data on the socket address and port. Once this event is raised, the socket is set to paused and no more onReceive events are raised for this socket.

The callback parameter looks like: ( info :   ReceiveErrorInfo ) =>   void

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-05-24 UTC.

How to connect to TCP Socket from browser using JavaScript?

  • Post author By John Au-Yeung
  • Post date September 5, 2022
  • No Comments on How to connect to TCP Socket from browser using JavaScript?

Labrador retriever puppy walking on green grass

To connect to TCP Socket from browser using JavaScript, we call the socket.create method.

For instance, we write

to call the socket.create method to create a socket to 127.0.0.1 port 8080.

We then call socket.connect method to connect to the socket with the socketInfo .

And then we call write to send data to the socket.

Related Posts

Sometimes, we want to connect client to server using Socket.io and JavaScript. in this article,…

Sometimes, we want to get browser height with JavaScript. In this article, we'll look at…

To get browser width using JavaScript, we can get the max of a few values.…

chrome.experimental.socket.create

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

sample extension for using socket API on Google Chrome

laclefyoshi/chrome_socket_sample

Folders and files, repository files navigation, chrome_socket_sample, introduction.

This is an extension using chrome.experimental.socket.* .

Install on Google Chrome Canary build https://tools.google.com/dlpage/chromesxs . Allow using experimental API on settings page.

Open popup of this extension. Input host, port of a server running udpserver.py and message and send.

If you want to use chrome.experimental.* API directly, open Inspect views of background.html of this extension with Developer tools.

  • Python 53.5%
  • JavaScript 46.5%

IMAGES

  1. How to Access Chrome's Experimental Features

    chrome.experimental.socket.create

  2. Does Google Chrome create a new socket for every HTTP request?

    chrome.experimental.socket.create

  3. How To Add Experimental Features In Chrome Using Command Line Switches

    chrome.experimental.socket.create

  4. Does Google Chrome create a new socket for every HTTP request?

    chrome.experimental.socket.create

  5. Chrome Flags: qué son y cómo puedes utilizar las funciones

    chrome.experimental.socket.create

  6. Google Chrome experimental new tab page

    chrome.experimental.socket.create

VIDEO

  1. 0.1 Introduction to Fun with WebSockets

  2. how to add idm extension to google chrome

  3. Chrome Developer Tools

  4. #1 Build a Powerful Node.js Express REST API with MySQL & Socket.io Integration |Step-by-Step Guide!

  5. Node JS

  6. Node JS