w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to receive web socket message from server in client side by html5 socket api
Its always good practice before connecting to websockets, to check if the browser your user is using supports them....like so.... //First check for firefox, and set it to regular websocket...since Mozilla API is differently named if (window.MozWebSocket) { window.WebSocket = window.MozWebSocket; } //Then continue with checking var connection = {}; function connect() { if(window.WebSocket != undefined) { if(connection.readyState === undefined || connection.readyState > 1) { connection = new WebSocket('ws://127.0.0.1:80'); } } }

Categories : PHP

Trying to make udp server echo back to udp client and print on the screen, as well have udp client receive messages
(If you read my earlier answer, please ignore it. It was incorrect.) You missed a '&' in front of addrlen on line 82 in udpserver.c. It should be: size = recvfrom(sock, buffer, nbytes, flags, (struct sockaddr *)&from, &addrlen); Other than that your code is working fine (I ran it). However, there are three things I would like to mention: The client does not need to to bind his socket to receive messages from the server. The server does not need to create a new socket to send messages to the client. Just use the socket you called recvfrom with. Sockets should be closed once they are not used anymore (even at the end of the program). Having too many open sockets will lead to not being able to create any new socket.

Categories : C

Java Socket server not recieving data from client socket
Your client doesn't close the socket. Your server reads the socket until EOS, which will never arrive as your client doesn't close the socket. NB don't handle client I/O in the accepting thread. Start a separate thread.

Categories : Java

Why do I received UDP socket answer randomly with Asynchronous UDP client socket?
That's how UDP works. UDP is a protocol that provides an unreliable, unordered data delivery between devices connected to an IP network. It is generally considered a "layer 4" protocol in the OSI stack. One popular use of UDP is for transport of time-sensitive information, such as Voice over IP. UDP is specified in RFC 768. http://www.techabulary.com/u/udp/ You either need to use TCP, or be prepared to handle the out-of-order (and possibly completely missing) responses. SCTP is another option for your transmission protocol.

Categories : C#

Socket.io : what happen to the client(socket) after a user is disconnected? Can I/Should I remove it?
In the code above, it is setInterval that is causing the additional logging. You will need to store off the id returned from setInterval then clear it using clearInterval on a disconnect event. Something like: io.sockets.on("connection",function(socket){ var intervalId = setInterval(function(){ console.log("Server calling update collection with socket No.",socket.No); },3000); //When connection is close() socket.on("disconnect",function(){ console.log("A user disconnected"); clearInterval(intervalId); }); }) Other than that, no need to do anything else with the socket on the server side. It will get garbage collected at some point.

Categories : Node Js

How to make client socket wait for server socket
boolean scanning=true; while(scanning) { try { socketChannel.open(hostname, port); scanning=false; } catch(ConnectionException e) { System.out.println("Connect failed, waiting and trying again"); try { Thread.sleep(2000);//2 seconds } catch(InterruptedException ie){ ie.printStackTrace(); } } } This is the code for sonics comment

Categories : Java

Chat client - Socket and server socket concurrently
ServerSocket blocks and that's it. But if you only want peer-to-peer communication between two connected parties and nothing more then this behavior is not a problem. You just need two programs: server and client. Server block until it gets connection from client and client blocks until it gets connection. If you want to implement Java IO in single thread you should use Java Nio. There are lots of tutorials for that in internet. For example http://tutorials.jenkov.com/java-nio/server-socket-channel.html. Also it seems that you are not very familar with networking and sockets so it might be beneficial to use some layer instead of raw sockets. Maybe you should consider JeroMQ (https://github.com/zeromq/jeromq) for implementing communication between programs.

Categories : Java

Client Socket Connections Being Denied By Server on Windows Host For Small Number (16 < x < 24) of Simulataneous Client Connection Attempts
I would check how many connections are in the TIME_WAIT state of the TCP connection. I have seen this type of problem due to many connections being open/closed causing socket exhaustion due to the TIME_WAIT. To check it, run: netstat -a

Categories : Java

The most efficient way to manage multiple socket(maximum 50 sockets.) in a single process?
Check some Open Source BitTorrent client and check the code to get some ideas, it is the best thing you could do. I recommend you to check BitTorrent in C or Hadouken in C# for example: https://github.com/bittorrent https://github.com/hadouken/hdkn

Categories : C

Socket.IO & private messages
I have built something like what you are saying. If a user can make a socket request, it pushes the message via the socket, and then the server does a broadcast or emit of it. But, if a user can't connect to the socket, it then does the http post, like what you are saying by calling the sendMessage. What I have done, rather than having sendMessage shoot off a socket is that I also have my clients doing an ajax request every 5 seconds or so. That will bring back new messages, and if any of the messages were not received via socket.io, I then add them to my clientside array. This acts as sort of a safety net, so I don't have to always fully trust socket.io. see below in pseudo code client if canSendSocketMessage() sendSocketMessage(message) else sendAjaxMessage(message) setInterv

Categories : Node Js

How to a variable can manage all client request
You need to use a static variable in your class that contains methodA(). class someClass { public static int counter = 0; void methodA() { counter++; //other code } } Now every time methodA is called, counter will be increased. I left it public so that you can access it from any class directly at any time to see how many times methodA() has been called.

Categories : Java

Sending messages to multiple rooms using Socket.io?
The sockets.in method only accepts one room as an argument, so to broadcast to multiple rooms you would have to reset the room, in between emissions. Something like this should work: ['room1', 'room2', 'room3'].forEach(function(room){ io.sockets.in(room).emit("id", {}); });

Categories : Node Js

how does socket.io send mess messages across multiple servers?
There are a few ways you can do this. More info in this question. A good explanation of how pub/sub in Redis works is here, in Redis' docs. An explanation of how the paradigm works in general is here, on Wikipedia. Quoting the Redis docs: SUBSCRIBE, UNSUBSCRIBE and PUBLISH implement the Publish/Subscribe messaging paradigm where (citing Wikipedia) senders (publishers) are not programmed to send their messages to specific receivers (subscribers). Rather, published messages are characterized into channels, without knowledge of what (if any) subscribers there may be. Subscribers express interest in one or more channels, and only receive messages that are of interest, without knowledge of what (if any) publishers there are. This decoupling of publishers and subscribers can

Categories : Node Js

Sails.js + socket.io: Sending messages from server to clients
The Sails way to do this would be to have a model backing your "Groups", and in a controller action have a socket subscribe to a group with Group.subscribe(groupId, req.socket). Then you can send messages to a specific group with Group.publish(groupId, data). You can also subscribe to an arbitrary room name in a controller using req.listen(groupId), and broadcast to that room with req.broadcast(roomName, data). This is all in the Sails documentation for working with Sockets!

Categories : Node Js

How to handle sending multiple messages over a socket connection?
You can use ObjectInputStream to read Objects instead of Strings. This way you will read only one Message(String in your case) every call to ObjectInputStream.readObject(); BTW you can read the first message, "do something" and then read the second message. you don't have to read all of the sent messages at once. If there are no other messages, then your thread will be blocked when trying to read an object from the ObjectInputStream. Use it like: ObjectInputStream inputStream = new ObjectInputStream( socket.getInputStream() )

Categories : Java

Slow socket's recv on Windows for lots of small messages
The way to manipulate the amount of kernel memory held for a socket in a Java program is to set SO_RCVBUF (in a C/C++ program you'd use setsockopt to do this). I'd rather not reproduced large amounts of code here but rather give you some pointers to look at. Documentation of SocketOptions Documentation of SO_RCVBUF You can use those to cut down the amount that the kernel will buffer before it returns stuff to you. That said, I can't see any reason why if your application has a SOCK_STREAM, it doesn't immediately return any data available. I think something else is likely the issue.

Categories : Java

How to send messages from server to client?
Sounds like a task for WebSockets. It is part of Java EE 7 so the Glassfish should be one of the first AS that will support it. For intercepting the DB access you can use @PostUpdate and @PostPersist. Here is related question. There are many ways to do the so called Server Push for notifying the connected clients: polling (the link you've provided in the question ("Are we there yet? Are we there yet? ...")) long polling (smarter way of polling - long-lived HTTP technique using keepalive messages) WebSockets (JSR 356) piggy-backing SPDY(wiki) Server-Sent Events (related answer, wiki) EDIT: In the Java world, there are couple of frameworks where server push (reverse ajax) is implemented out-of-the box. If you are familiar with GWT, I would suggest Errai. Other alternative is the Atmosp

Categories : Mysql

Unable to receive messages in browser client
I've just configured Faye for our application, you are doing bayeux.attach(app); app.listen(port); did not work for me, what worked is this bayeux.attach(app.listen(port, function() {})); I also think that you should use the whole url when you are creating Faye, not just the final part, like so: var client = new Faye.Client('http://my.url.com/faye', { timeout: 20 });

Categories : Node Js

WebSocket messages get queued when client disconnected
Browsers may handle websocket client messages in a separate thread, which is not blocked by sleep. Even if a thread of your custom application is not active, when you force it to sleep (like sleep(100)), TCP connection is not closed in this case. The socket handle is still managed by OS kernel and the TCP server still sends the messages until it reaches the TCP client's receive window overflow. And even after this an application on server side can still submit new messages successfully, which are buffered on TCP level on server side until TCP outgoing buffer is overflown. When outgoing buffer is full, an application should get error code on send request, like "no more space". I have not tried myself, but it should behave like this. Try to close the client (terminate the process), you wi

Categories : Python

How do I add SSL to an NIO socket client?
You need to use the SSLEngine, which is no joke in itself, and I'm not sure it works correctly on Android, although I am open to correction. The SSLEngine is a state machine and takes a lot of implementing. Frankly having done it I would forget it and use SSLSockets.

Categories : Java

logging error messages in a log file for the client using a web application
Perhaps something like Log4Net would be sufficient for your needs. In the end you could even provide a UI to handle these problematic entries in your application. So why not store them in your db and then show them in a custom UI where users can handle the issues one by one in a collaborative manner?

Categories : C#

Python flask and custom client error messages
you can directly put a custom response in abort() function: abort(make_response("Integrity Error", 400)) Alternatively, you can put it in the error handler function @app.errorhandler(400) def not_found(error): resp = make_response("Integrity Error", 400) return resp

Categories : Python

WCF Web socket client also need to run on windows 8
You will need win8 or 2012server to be able to use the Microsoft WebSocket namespace in your WCF. You could also take a look at SignalR that will fallback to other techniques when WebSockets is not available. You can also use XSockets.NET that will run websockets on .NET 4 (so there is no need for win8 or 2012server). You also have SuperWebSocket and Fleck as options of .NET 4. Edit: Added sample with WebSockets from WCF .NET 4 here https://github.com/XSockets/XVA/tree/master/XVA-07-02-BoostWCF/Any%20OS

Categories : Wcf

I want to get a client socket using FCGI.pm
I solved this problem. #!/usr/bin/perl use strict; use warnings; use FCGI; use Socket; my $socket = FCGI::OpenSocket(":9000", 5); my $request = FCGI::Request(*STDIN, *STDOUT, *STDERR, \%ENV, $socket); my $count = 1; while($request->Accept() >= 0) { print "Content-Type: text/html; charset=UTF-8 "; print $count++, "<br />"; print "$$<br />"; open(my $client, "+>&4") or die "$!"; my $mysockaddr = getsockname($client) or die "$!"; my ($myport, $myaddr) = sockaddr_in($mysockaddr); print $myport, ":", inet_ntoa($myaddr), "<br />"; my $peersockaddr = getpeername($client) or die "$!"; my ($peerport, $peeraddr) = sockaddr_in($peersockaddr); print $peerport, ":", inet_ntoa($peeraddr), "<br />"; close $client;

Categories : Perl

Can Client Socket Connection be anything?
As Keith stated, the "ComputerName" you specify when creating the socket is the DNS name of the machine. That means that when you create the socket, your computer does a DNS lookup to determine the IP address of the server you're trying to connect with. As zapl stated, Windows computer names are != to DNS names (they're unknown by the DNS server that does the resolution). Java sockets can also be created using an InetAddress, which is the preferred method because in many cases your server won't have it's name registered with the DNS.

Categories : Java

Alternative Socket IO Client
socket.io supports various transports such as flashsockets and XHR long-polling. So you do not have to use a different client - it should work out of the box even without Websocket support Speaking of alternatives... there are some client libraries e.g. for Python but I don't think there are any that run in the browser - as I said before, there's no need for them.

Categories : HTML

Where to change i18n default messages of client side in Grails?
I think you are missing 'invalid' as part of the message key. Use the following error code for matches: className.propertyName.matches.invalid = 'errorMessage'..

Categories : Grails

Java Client driven by asynchronous events(xml messages) over a TCP Connection
I would be extremely surprised if you cannot handle the messages serially (unless you client performs particularly badly) I would use a simple IO socket and a STaX event parser to decode the messages. The Javolution XML parser is pretty quick. I don't like Spring because it tends to make complex solutions of simple problem IMHO. You should be able to do all this with just one class file and a few small nested classes. Don't be afraid to write the code yourself, this is how you become a more experienced developer. I would expect you should be able to handle 1000+ large XML messages per second and as much as 200,000 small XML messages per second with one reader thread.

Categories : Java

How can the WCF RoutingService route callback messages from two different WCF servers with the same contract to a client?
You should set a specific priority adding SVC1 & SVC2 to the FilterTable. routingConfiguration.FilterTable.Add(new MatchAllMessageFilter(), new List<YourServiceType> { yourService }, 1); Further info here.

Categories : C#

How to push changes in a database to the client using socket.io?
It sounds like you want to have socket.io also on the client side (browser?) as well. I'd say the best solution would be to have socket.io run on the same port as your web server. However, if it this not possible and you must keep the web socket that the database uses separate from the web server you could run two instances of socket.io. One would be attached to the web server, and the other would be for the database. var app = require('http').createServer(handler) , IO = require('socket.io') , web_io = IO.listen(app) , data_io = IO.listen(8080) , fs = require('fs') app.listen(80); function handler (req, res) { fs.readFile(__dirname + '/index.html', function (err, data) { if (err) { res.writeHead(500); return res.end('Error loading index.html'); }

Categories : Javascript

Socket chat client error
from socket import * You've imported the entire socket module. There is no socket.socket. You've imported the socket object directly into the current namespace. To access it, simple do s = socket((socket.AF_INET, socket.SOCK_STREAM)) If you had done import socket Then you could access the socket object via the module namespace.

Categories : Python

Socket programming between client in C#.NET and server in C
Socket is universal concept and not specific to any language. You can go ahead and use the same C Ubuntu Server code and C# Windows Client code. Few Things you need to take care of are : How you bind the server & client and protocol used. Firewall settings. Hope you can kick start with these inputs Happy Coding :)

Categories : C#

Socket Programming in C(Client Server Example)
sockfd=socket(AF_INET,SOCK_STREAM,0); bzero(&serveraddr,sizeof(serveraddr)); serveraddr.sin_family=AF_INET; serveraddr.sin_port=htons(7400); inet_pton(AF_INET,servername,&serveraddr.sin_addr); // here You're passing servername to inet_pton() but it is not initialized ! So inet_pton() will fail. You should check its return value. servername=gethostbyname(); //here addr_size=sizeof(serveraddr); The second problem is that you're not using gethostbyname() correctly.Take a look at the manpage, you will see that gethostbyname() is taken arguments and it returns a pointer to a struct hostent, not a pointer to char like you did. Your compiler doesn't warn you about this because you don't include netdb.h. You should check the return values of all the functiond that you are using, it's

Categories : C

How to send a message to a particular client with socket.io
You can refer to socket.io rooms. When you handshaked socket - you can join him to named room, for instance "user.#{userid}". After that, you can send private message to any client by convenient name, for instance: io.sockets.in('user.125').emit('new_message', {text: "Hello world"}) In operation above we send "new_message" to user "125". thanks.

Categories : Javascript

client not receiving data via TCP socket
It might help to follow the flow. The "app=ipbcc(root)" step would call "self.connect()" and that has a "def xloop():" that has the step "data=clientsock.recv". But, then somebody needs to invoke xloop(). Who does that? Btw, why do have a function inside a method? Also, I don't see anybody invoking the "clientsock.send(msg.encode())" via the write() method. I am not familiar with the Tinker part (and what the mainloop() does), so can you please check if there are callers to send() and the recv() call.

Categories : Python

Server Client Socket Programming
I think the key is how do you identify a client, so that once it comes back, you expect hte server to remember it. I dont see the logic in the server code where it keeps track of the client. Having said that, one way to identify the TCP client is to use the IP address and port number of the client. If we close that TCP client and restart it again, the port number of the client may not be guaranteed since most of hte TCP clients do not call bind() and simply use connect() to get an ephemeral port number. Or, you could use an application layer logic (remember the application sits on top of TCP), where the client can use a unique identifier or can ask the server to provide it a unique identifer. So, when the client comes back, it then tells the server that it has a identifier and it would li

Categories : Java

Tunneling two socket client in java
I would do it this way (simplified version): class Server extends Thread ... public void run() { while (true) { try { Socket s1 = server.accept(); Socket s2 = server.accept(); new Client(s1, s2).start(); // reads from s1 and redirects to s2 new Client(s2, s1).start(); // reads from s2 and redirects to s1 } catch (IOException e) { System.out.println("Client connection error: " + e.getMessage()); } } } class Client extends Thread { Socket s1; Socket s2; Client(Socket s1, Socket s2) { this.s1 = s1; this.s2 = s2; } public void run() { try { Inp

Categories : Java

Socket event for specified Android client
When client connects on server side, you have handle of socket and it has ID socket.id. This ID is unique per socket so you can use it to identify sockets. So on connection you can make your own arrays of sockets and push them there. Then you can iterate through them and emit any message. It is not necessary to use built-in rooms for this, and you can make yours easily. So Identifying sockets your own way - will allow you to manage them better and will give you ability to send messages to specific socket. As far as there is a way to reference it using ID or any other identification method.

Categories : Android

WCF Client-Server Socket Timeout
Odds are there is no timeout issue but you're hitting a timeout after no answer, not due to time, but due to an issue causing it to never answer (5minutes is already huge). The best way to diagnose it is to change the configuration (on both the client & server side) to log WCF events http://msdn.microsoft.com/en-us/library/ms730064.aspx And then view them on the server, if the server side is empty, then it's not receiving any connection & moving to the client's log may tell you more about the error, if you still get nothing out of it, contact the network administrator, it most likely is a network issue.

Categories : C#

event machine websocket server: how to push periodic messages to client?
I found a solution myself: In the code below, server push a websocket message to client every 500 msec. ( PeriodicTimer.new(0.5) ). The problem I have now, is how to dinamically reset the timer to send a message every N msecs where N is a random value... Any idea ? require 'eventmachine' require 'em-websocket' require 'socket' EM.run { EM::WebSocket.run(:host => "0.0.0.0", :port => 8080) do |ws| ws.onopen { |handshake| puts "WebSocket connection open" ws.send "Hello Client, you connected to: #{Socket.gethostname}. websocket server path: #{handshake.path}" timer = EventMachine::PeriodicTimer.new(0.5) do value = (rand(100..6000) / 1000.0 ) message = "time: #{Time.now} value: #{value.to_s}" ws.send message puts message end

Categories : Ruby On Rails



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.