w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
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#

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

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

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

File corrupt from asynchronous tcp socket
The primary problem is in your receive code on the server. You're converting binary data to a string with this: // There might be more data, so store the data received so far. state.sb.Append(Encoding.ASCII.GetString( state.buffer, 0, bytesRead)); ASCII is a 7-bit encoding. Any character that is not in the range 0 to 127 will be converted to "?". So approximately half of your binary data is getting converted to question marks. Another problem you'd have here is if the string "<EOF>" occurs somewhere in a text file (or a binary file). If that happened, your receiver would quit before the entire file were read. You should change your protocol so that rather than sending an "<EOF>" string, you put the total length of what you're sendin

Categories : C#

Asynchronous Socket Read Issue
Everything is effectively thread-safe if it is in isolation; the important question is: what else is going on? What else is accessing (read or write) the dictionary? If nothing, then you should be fine - the callback will be invoked (which depending on the specific API being used, and the data available in the buffer, could be either on the thread issuing Read..., or on a completion-port thread), and then presumably you'll do some work with the dictionary before doing something else (read/write/close). If, however, other threads are accessing the dictionary, then the question is impossible to answer without specific code.

Categories : C#

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

Asynchronous Socket Server Hangs Intermittently
So this issue turned out to be network specific. We are using a satellite modem that sends data to a hub, the hub connects to our server to send the data from the sat modem. The hub for our satellite provider is not closing the connection to the server after no more data is available from the socket. My solution was to add a timer to my state object for my asynchronous socket server and close it if no data has been received after a period of time. public class StateObject : IDisposable { // Client socket. public Socket workSocket = null; // Size of receive buffer. public static int BufferSize = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ListenerBufferSize"]); // 32768; //32kb buffer // Receive buffer. public by

Categories : C#

Multiple socket connections using asynchronous sockets
How do I modify this code such that it iterates through my whole list of IPs Your code will iterate the whole list. But it will get to the second address only after it receives all data from the first address. How do I modify this code such that it connects to all the IPs at once. If you encapsulate the code for a single address into a separate async method, you can then first call it for each address and then await all the returned Tasks. Or you could use LINQ: private async void button1_Click(object sender, EventArgs e) { var listOfIps = new List<string> { "192.168.168.193", "192.168.168.221" }; await Task.WhenAll(listOfIps.Select(ip => ReadFromAddress(ip))); } private async Task ReadFromAddress(string address) { IPEndPoint remoteEP = new IPEndPoint(IPAd

Categories : C#

What is the difference between synchronous and asynchronous transmission in TCP/ IP socket programming?
TCP transmission is always asynchronous. What's synchronous or asynchronous is the behaviour of the API. A synchronous API does things while you call it: for example, send() moves data to the TCP send buffer and returns when it is done. An asynchronous API starts when you call it, executes independently after it returns to you, and calls you back or provides an interrogable handle via which completion is notified. HTTP is synchronous in the sense that you send a request, receive a response, display or process the response, all in that order. Ajax is asynchronous only in the sense that it operates independently of the page request/response cycle in the surrounding HTTP request. It's a poor choice of terminology. It would have been better to use a term like 'nested', 'out of band', ...

Categories : Multithreading

Efficient socket I/O using Task-based Asynchronous Pattern (TAP)
At this time, there are no examples of good approaches for this. Once you get a solution working, I'd recommend publishing it somewhere. 1. I need an asynchronous "task" that never completes to receive the data... I disagree with the statement "a socket receive never completes in the traditional sense". The lower-level "receive" operation (e.g., a FromAsync wrapper around BeginReceive/EndReceive or Toub's ReceiveAsync) returns a Task that will complete when there is data available, the socket is closed, or there is an error. The higher-level "receiver" operation (e.g., ReadAsync from Toub's post) will complete when the socket is closed or there is an error. You can have Tasks that could take an indefinite amount of time to complete, but as long as they do complete that's fine. What

Categories : Dotnet

How to do a asynchronous set in Couchbase PHP client library
I'm wondering what the purpose would be ... the async get makes sense ... you send a bunch of keys and get a response whenever the data is sent back to you. With a set you're going to send the data to the server. The couch server will cache the data in memory and return instantly. My understanding is that it queues it for disk writing. After writing to disk it queues it for indexing of views. There really isn't much to "delay". It returns to you immediately after writing it to memory. There isn't anything to do asynchronously is there? The only thing I could think of is the driver could cache it for you before sending it the couch server, but I'm not sure that would accomplish much except for using memory in the couch client (harder to debug oom errors).

Categories : PHP

difference between synchronous and asynchronous client
From EAI Patterns: In a synchronous implementation of a Web Service, the client connection remains open from the time the request is submitted to the server. The client will wait until the server sends back the response message.... At the present time, most Web Services toolkits only support synchronous messaging by default. However, using existing standards and tools such as asynchronous message queuing frameworks, some vendors have emulated asynchronous messaging for Web Services. In asynchronous clients, clients should be able to handle incoming data from server after server has done its job. Asynchronous requests are like 'fire and forget' mechanism. Target will inform you about the progress.

Categories : Eclipse

Set Timeout on Asynchronous Http Client
The library seems to be doing what you want it to do, setTimeout code from the AsyncHttpClient class public void setTimeout(int timeout){ final HttpParams httpParams = this.httpClient.getParams(); ConnManagerParams.setTimeout(httpParams, timeout); HttpConnectionParams.setSoTimeout(httpParams, timeout); HttpConnectionParams.setConnectionTimeout(httpParams, timeout); } If it is not working then better report the issue here

Categories : Android

Asynchronous server and client with named pipes
You are supposed to use following functions during asynchronous modes: NamedPipeClientStream.BeginRead NamedPipeClientStream.EndRead and NamedPipeServerStream.BeginWrite NamedPipeServerStream.EndWrite Also I am convinced proper implementation for WaitForPipeDrain() is always used before any writes to buffer because if you have previously written, you will need to check whether previous write to buffer has been read. If you write and then use WaitForPipeDrain() then subsequent call to your write function (even mistakenly) will overwrite first and then check. I haven't tried it but it can be logically thought to be so.

Categories : C#

How to call asynchronous HTTP client in Restlet with timeout
Take a look at the following discussion, it discusses two issues which might be causing the problem. http://restlet-discuss.1400322.n2.nabble.com/Using-Asynch-setOnResponse-td7578750.html

Categories : Java

What is the right way to handle asynchronous behavior on Meteor's client side?
This is a common use case, acceptably solved, no need to think too deeply. Making HTTP requests, and using the results. If you get an URL back, save to session. Set a template to be based on that session var, and it will automatically refresh once the callback updates the session. http://docs.meteor.com/#http HTTP.call("POST", "http://api.twitter.com/xyz", {data: {some: "json", stuff: 1}}, function (error, result) { if (result.statusCode === 200) { Session.set("twizzled", true); } }); ***************************8 To the rabid downvoters: This is a brand new technology, rapidly changing, and just getting started. It is not hard to find info from a few months back that is inaccurate. Let's be a little less quick

Categories : Javascript

Android Asynchronous Http Client never seems to call back
I think you forget add permission in your AndroidManifest file: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> Read more about Manifest file here. UPDATED: Here is an example of manifes file from loopj github <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.loopj.android.http" android:versionName="1.4.3" android:versionCode="1"> <application android:name="android_async_http"> </application> <uses-sdk android:minSdkVersion="3" /> <uses-permission android:name="android.permission.INTERNET" /> </manifest> You can see INTERNET permission

Categories : Android

How to make asynchronous calls from a WCF client to WCF Service in parallel
You need to make the client calls asynchronous. If you're using VS 2012, you can enable the Task based asynchronous calls in the service reference, then call via: var task1 = proxy.PrintCustomerHistoryAsync(customerListOne, @"c:DestinationOne"); var task2 = proxy.PrintCustomerHistoryAsync(customerListTwo, @"c:DestinationTwo"); // The two tasks are running, if you need to wait until they're done: await Task.WhenAll(task1, task2);

Categories : C#

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

Associating responses with specific requests using Loopj Android Asynchronous Http Client
Try this: public class MyAsyncHttpResponseHandler extends AsyncHttpResponseHandler { private String requestId; public AsyncHttpResponseHandler(String requestId) { this.requestId = requestId; } @Override public void onSuccess(String arg0) { super.onSuccess(arg0); // Use requestId here } } Sending request: client.get(url, new MyAsyncHttpResponseHandler(requestId))

Categories : Android

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

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

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

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

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

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

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

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#

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

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#

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

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

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

Has server opened socket for each client process?
Usually, on the server side, after the socket is created and bound to a particular port/address combination, a function called Listen (or similar) will be called. This makes this bound socket a listening socket - it's just waiting for connection attempts to start. After this, there will be a call to a function called something like Accept on the listening socket. This call will take a pending connection request from the listening socket, create a new socket, and return that. All further communication between the client and the server will be via this new socket (at the server end), for the duration of the connection. Different techniques may be used to achieve scalability if the server needs to be handling multiple client connections simultaneously. One simple technique (which doesn't s

Categories : Sockets

Java socket polling for checking if client is available
WHy not do a receive call and then catch exceptions. If you get a broken pipe exception or socket timeout, then you know that the client is no longer present. For such cases, the typical approach is for the server to set TCP keepalive using the setKeepAlive and getKeepAlive methods. http://docs.oracle.com/javase/6/docs/api/java/net/Socket.html . If the client goes away, then TCP keepalive would kick in (becuase of inactivity) and it would detect that the client is disconnected. Then, it will close the connection. Any subsequent recv() call would return with a value of -1 and error indicating the same.

Categories : Java



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