Skip to content

"tcp server" app doesn't write to client connections #82

Closed
ravindrapai opened this Issue Apr 1, 2013 · 7 comments

5 participants

@ravindrapai

Steps to Reproduce:

1) launch the extension
2) click start buttion for 127.0.0.1 and port 8888.
3) i ran a tcp client in python to send some data and recv it back.
eg:

 #!/usr/bin/env python

import socket

TCP_IP = '127.0.0.1'
TCP_PORT = 8888
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

I have seen in the code that server does call write for received message.
From the code,

tcpserver/main.js line 67:
        try {
          tcpConnection.sendMessage(Commands.run(cmd[0], cmd.slice(1)));
        } catch (ex) {
          tcpConnection.sendMessage(ex);
        }

System information:

$ uname -a
Linux 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

2) chrome version:
Version 25.0.1364.172

@rpaquay rpaquay was assigned by scheib May 30, 2014
@scheib scheib added the bug label May 30, 2014
@dinhviethoa
GoogleChrome member

Does it still happen with recent versions of Chrome?

@beaufortfrancois
GoogleChrome member

It is stil happening with Google Chrome 38.0.2125.8 (Official Build 290962) dev
The trick for me is to wait a little bit after connecting before sending a message to be sure the connection is well established I guess.

Here's an updated version of your code:

#!/usr/bin/env python

from time import sleep
import socket

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

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))

sleep(0.1) # Waiting helps..
s.send(MESSAGE)
data = s.recv(BUFFER_SIZE)
s.close()

print "received data:", data

@rpaquay Any idea on what is happening there?

@beaufortfrancois
GoogleChrome member

The beaufortfrancois@b8632cc patch is coming soon and will fix this issue.

@rpaquay
rpaquay commented Aug 26, 2014

Yeah, using the "new" chrome.sockets API from #205 should fix this issue. I think the problem with the old/current sample is that it doesn't properly handle simultaneous connections properly, it only handles accept/recv/send/close sequences of events. If you use IE for example, the server hangs all the time because IE tries to load favicon.fav at the same time it hit the url.

@beaufortfrancois
GoogleChrome member

Actually #205 wasn't fixing the issue.

The root problem exists because the tcp connection was starting to listen before addDataReceivedListener was set.

@rpaquay
rpaquay commented Aug 26, 2014

Oh I see, yes, you are correct. Apologies, I was thinking about another issue (multiple connections actives).

@beaufortfrancois
GoogleChrome member

The tcpServer sample app has been updated to the new sockets API #283

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.