urlserver = {
'socket' : None,
'http_scheme_display': ('http', 'display this scheme in shortened URLs'),
'http_hostname' : ('', 'force hostname/IP in bind of socket (empty value = auto-detect current hostname)'),
scheme = urlserver_settings['http_scheme_display']
hostname = urlserver_settings['http_hostname_display'] or urlserver_settings['http_hostname'] or socket.getfqdn()
port = urlserver_settings['http_port_display']
elif urlserver['socket']:
port = urlserver['socket'].getsockname()[1]
global urlserver
if urlserver['socket']:
weechat.prnt('', 'URL server listening on %s' % str(urlserver['socket'].getsockname()))
else:
global urlserver, urlserver_settings
if urlserver['socket']:
hacked from my original interactive version. A further hack allows it to listen
on a Unix domain socket as an alternative to a TCP/IP port.
In an IPv6 world, listening happens on both an IPv6 and an IPv4 socket, always
#define v6n 0 /* IPv6 socket number */
#define v4n 1 /* IPv4 socket number */
#define udn 2 /* Unix domain socket number */
#define skn 2 /* Potential number of sockets */
int port = 0;
int listen_socket[3] = { -1, -1, -1 };
int accept_socket;
{
if (debug) printf("%d: Creating Unix domain socket\n", time(NULL));
listen_socket[udn] = socket(PF_UNIX, SOCK_STREAM, 0);
if (listen_socket[udn] < 0)
int flushbuffer (int socket, uschar *buffer)
int retval, rsp;
rsp = write(socket, buffer, Ustrlen(buffer));
DEBUG(D_acl)
debug_printf("DCC: Error writing buffer to socket: %s\n", strerror(errno));
DEBUG(D_acl)
debug_printf("DCC: Wrote buffer to socket:\n%s\n", buffer);
/**************************************
* Now creating the socket connection *
/* If sockip contains an ip, we use a tcp socket, otherwise a UNIX socket */
serv_addr_in.sin_port = htons(portnr);
if ((sockfd = socket(AF_INET, SOCK_STREAM,0)) < 0){
DEBUG(D_acl)
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
// Name for the SDP record when creating server socket
// Start the thread to listen on a BluetoothServerSocket
*
* @param socket
* The BluetoothSocket on which the connection was made
* @param device
*/
public synchronized void connected(BluetoothSocket socket,
// Start the thread to manage the connection and perform transmissions
mConnectedThread = new ConnectedThread(socket);
static void tds_put_params(TDSSOCKET * tds, TDSPARAMINFO * info, int flags);
static void tds7_put_query_params(TDSSOCKET * tds, const char *query, size_t query_len);
static void tds7_put_params_definition(TDSSOCKET * tds, const char *param_definition, size_t param_length);
static TDSRET tds_put_data_info(TDSSOCKET * tds, TDSCOLUMN * curcol, int flags);
static inline TDSRET tds_put_data(TDSSOCKET * tds, TDSCOLUMN * curcol);
static char *tds7_build_param_def_from_query(TDSSOCKET * tds, const char* converted_query, size_t converted_query_len, TDSPARAMINFO * params, size_t *out_len);
static char *tds7_build_param_def_from_params(TDSSOCKET * tds, const char* query, size_t query_len, TDSPARAMINFO * params, size_t *out_len);
static TDSRET tds_put_param_as_string(TDSSOCKET * tds, TDSPARAMINFO * params, int n);
static TDSRET tds_send_emulated_execute(TDSSOCKET * tds, const char *query, TDSPARAMINFO * params);
static TDSRET
tds_query_flush_packet(TDSSOCKET *tds)
static inline TDSRET
tds_put_data(TDSSOCKET * tds, TDSCOLUMN * curcol)
// the network with PubNub services.
// It allow to establish socket connection and
// Stores reference on buffer which should be sent to the PubNub service via socket
// Socket streams and state
@property (nonatomic, assign) CFReadStreamRef socketReadStream;
@property (nonatomic, assign) CFWriteStreamRef socketWriteStream;
@property (nonatomic, assign, getter = isWriteStreamCanHandleData) BOOL writeStreamCanHandleData;
// Socket streams configuration and security
/**
* Called each time when new portion of data available in socket read stream for reading
// Server disconnected socket probably because of timeout
class Send(threading.Thread):
def __init__(self, socket, screen):
#Initialize Input Values
self.socket = socket
self.running = False
rankings = Rankings(self.socket, self.screen, self.lead)
class TextMenu:
def __init__(self, socket, screen):
self.screen = screen
self.socket = socket
self.running = False
self.socket.connect((self.ipAddress, int(self.port)))
send = Send(self.socket, self.screen)
self.running = False
textmenu = TextMenu(self.socket, self.screen)
function isFinished(msg) {
var socket = msg.socket
// OutgoingMessage
return Boolean(msg.finished || (socket && !socket.writable))
// IncomingMessage
return Boolean(!socket || !socket.readable || (msg.complete && !msg.readable))
var eeMsg
var eeSocket
eeMsg.cancel()
eeSocket.cancel()
// finished on first message event
eeMsg = eeSocket = first([[msg, 'end', 'finish']], onFinish)
function onSocket(socket) {
// remove listener
%%
-record(session, {% The connection socket.
% and send messages to it.
socket :: port(),
-spec start_link(port()) -> _.
start_link(ListenSocket) ->
gen_server:start_link(?MODULE, ListenSocket, []).
%% At first, the state of the server is simply the listening socket. This is
end,
inet:setopts(Session1#session.socket, [{active, once}]),
{noreply, Session1};
handle_info({tcp_closed, Socket}, Session = #session{socket = Socket}) ->
{stop, normal, Session};
handle_info({tcp_error, Socket, Reason}, Session = {socket = Socket}) ->
/**
* WebSocket Server Settings
* (sails.config.sockets)
*
* These settings provide transparent access to the options for Sails'
* encapsulated WebSocket server, as well as some additional Sails-specific
*
* For more information on sockets configuration, including advanced config options, see:
* http://sailsjs.org/#/documentation/reference/sails.config/sails.config.sockets.html
*/
module.exports.sockets = {
* *
* This custom onConnect function will be run each time AFTER a new socket *
* connects (To control whether a socket is allowed to connect, check out *
connect(&socket, SIGNAL(connected()), this, SLOT(socketConnected()));
connect(&socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
connect(&socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(socketError(QLocalSocket::LocalSocketError)));
connect(&socket, SIGNAL(bytesWritten(qint64)), this, SLOT(socketWritten(qint64)));
connect(&socket, SIGNAL(readyRead()), this, SLOT(socketReading()));
connect(&server, SIGNAL(newConnection()), this, SLOT(newInstanceConnected()));
} else {
DEBUG_LOG(("Application Info: connecting local socket to %1..").arg(serverName));
socket.connectToServer(serverName);
}
void Application::socketConnected() {
DEBUG_LOG(("Application Info: socket connected, this is not the first application instance, sending show command.."));
closing = true;
using System.Net;
using System.Net.Sockets;
{
// Client socket.
public Socket workSocket = null;
// Size of receive buffer.
public class AsynchronousSocketListener
public AsynchronousSocketListener()
// Establish the local endpoint for the socket.
// Create a TCP/IP socket.
Socket listener = new Socket(AddressFamily.InterNetwork,
# Create QMUX deamon socket area
mkdir /dev/socket/qmux_radio 0770 radio radio
chmod 2770 /dev/socket/qmux_radio
mkdir /dev/socket/qmux_audio 0770 media audio
chmod 2770 /dev/socket/qmux_audio
mkdir /dev/socket/qmux_bluetooth 0770 bluetooth bluetooth
chmod 2770 /dev/socket/qmux_bluetooth
mkdir /dev/socket/qmux_gps 0770 gps gps
chmod 2770 /dev/socket/qmux_gps
# Change to socket location on libkeyctrl/suntory for /data encryption
mkdir /dev/socket/suntory 0755 system system
int security_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
{
return security_ops->socket_connect(sock, address, addrlen);
int security_socket_listen(struct socket *sock, int backlog)
{
return security_ops->socket_listen(sock, backlog);
int security_socket_accept(struct socket *sock, struct socket *newsock)
{
return security_ops->socket_accept(sock, newsock);
int security_socket_sendmsg(struct socket *sock, struct msghdr *msg, int size)
{
static inline u16 socket_type_to_security_class(int family, int type, int protocol)
case SOCK_SEQPACKET:
return SECCLASS_UNIX_STREAM_SOCKET;
case SOCK_DGRAM:
return SECCLASS_UNIX_DGRAM_SOCKET;
if (default_protocol_stream(protocol))
return SECCLASS_TCP_SOCKET;
else
return SECCLASS_RAWIP_SOCKET;
if (default_protocol_dgram(protocol))
return SECCLASS_UDP_SOCKET;
else
case NETLINK_SELINUX:
return SECCLASS_NETLINK_SELINUX_SOCKET;
* Transmit calls pass in kernel virtual addresses and block copying this into
* the socket's tx buffers via a usual blocking sendmsg. They'll block waiting
* for a failed socket to timeout. TX callers can also pass in a poniter to an
* 'int' which gets filled with an errno off the wire in response to the
*
* Handlers for unsolicited messages are registered. Each socket has a page
* that incoming data is copied into. First the header, then the data.
* Handlers are called from only one thread with a reference to this per-socket
*
* Our sock_container holds the state we associate with a socket. It's current
* framing state is held there as well as the refcounting we do around when it
* is safe to tear down the socket. The socket is only finally torn down from
* the container when the container loses all of its references -- so as long
* as you hold a ref on the container you can trust that the socket is valid
* for use with kernel socket APIs.
import time, string, random, socket, os, signal, re, logging, commands, cPickle
s = socket.socket()
#s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if address == "localhost":
free = False
except socket.error:
index = 0
ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
"""
ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
"""
ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
"""
ctrl_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
import os, pickle, random, re, resource, select, shutil, signal, StringIO
import socket, struct, subprocess, sys, time, textwrap, traceback, urlparse
def normalize_hostname(alias):
ip = socket.gethostbyname(alias)
return socket.gethostbyaddr(ip)[0]
def try_bind(port, socket_type, socket_proto):
s = socket.socket(socket.AF_INET, socket_type, socket_proto)
try:
try:
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s.getsockname()[1]
except socket.error:
# On the 2.6 kernel, calling try_bind() on UDP socket returns the
<dt><b>wsi</b>
<dd>Websocket instance (available from user callback)
<dt><b>buf</b>
<dd>The data to send. For data being sent on a websocket
of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
data on a websockets connection. Remember to allow the extra
This function provides the way to issue data back to the client
for both http and websocket protocols.
<p>
<dt><b>context</b>
<dd>Websocket context
<dt><b>origin</b>
<dd>Socket origin name
<hr>
<h2>lws_client_connect_extended - Connect to another websocket server</h2>
#include <sys/types.h>
#include <sys/socket.h>
/* Maximum length for a unix socket pathname */
*/
if ((fd = socket((int) addr->sa_family, SOCK_STREAM, 0)) < 0)
#if defined(ECL_MS_WINDOWS_HOST)
closesocket(fd);
* Creates a server port. Returns file
* descriptor (network socket) or 0 if connection fails.
{
struct sockaddr_in inaddr; /* INET socket address. */
int addrlen; /* length of address */
int request, conn; /* Network socket */
*/
if ((request = socket(AF_INET, SOCK_STREAM, 0)) < 0) {