Posts

python - blocking recv() returns empty line instead of actual data -

i'm working on python client supposed converse c programmed server. answers few recognised commands "ok" (the server part works when test netcat client). python client gets ok 1 out of 4 times (and empty lines rest of time). don't why socket set blocking figure receive don't know what. here have. "info" object few strings stored in it, before loop works , bit simplified readability : i'm supposed receive welcome message send team name of connected player receive position. try: s = socket.socket(socket.af_inet, socket.sock_stream) except socket.error, msg: print 'failed create socket. error code: ' + str(msg[0]) + ' , error message : ' + msg[1] sys.exit(); try: remote_ip = socket.gethostbyname(info.host) except socket.gaierror: print "hostname not resolved. exiting" sys.exit() s.setblocking(1) s.settimeout(60) s.connect((remote_ip, info.port)) data = s.recv(1024) print data team = info.team ...

linux - perl's Devel::ebug how to -

first apologize if misunderstood whole concept of devel::ebug , how should used. want experiment devel::ebug perl module. here found example: what perl equivalent of bash -xv took following code , modified little bit. according official documentation devel::ebug cpan program method selects program load, thing i've changed. #!/usr/bin/perl use strict; use warnings; use devel::ebug; use data::dumper; $ebug = devel::ebug->new; # $ebug->program(shift); # old value: $ebug->program($argv[0]); # new value: $ebug->load; until ($ebug->finished) { print "+++ file:", $ebug->filename, " line: ", $ebug->line, "\n"; $pad = $ebug->pad; $var (sort keys %$pad) { if (ref $pad->{$var}) { $line (split /\n/, data::dumper->dump([$pad->{$var}], [$var])) { print "++ $line\n"; } } else { print "++ $var = $pad->{$var}\n"; ...

rssi - Interpreting the value I receive from the ATDB command for Xbee S2 -

i realize might stupidest question has ever been asked here, i'm stuck. trying rssi value of xbee router send atbd coordinator. value returned in hexadecimal cannot, life of me, see how hexadecimal value interprets dbm value. actually command isn't atbd, atdb , means: " received signal strength. command reports received signal strength of last received rf data packet. db command indicates signal strength of last hop. not provide accurate quality measurement multihop link. db can set 0 clear it. db command value measured in -dbm. for example if db returns 0x50, rssi of last packet received -80dbm . of 2x6x firmware, db command value updated when aps acknowledgment received." (retired xbee zb user manual p.131). as can see example above, need to: read hexadecimal (example: 0x50) read decimal (example: 0x50 = 80 in decimal) multiply -1: (-1)*80 = -80 dbm the atbd command used change serial interface data rate (baud rate).

c++ - std::conditional compile-time branch evaluation -

compiling this: template < class t, class y, class ...args > struct issame { static constexpr bool value = std::conditional< sizeof...( args ), typename std::conditional< std::is_same< t, y >::value, issame< y, args... >, // error! std::false_type >::type, std::is_same< t, y > >::type::value; }; int main() { qdebug() << issame< double, int >::value; return exit_success; } gives me compiler error: error: wrong number of template arguments (1, should 2 or more) the issue issame< double, int > has empty args parameter pack, issame< y, args... > becomes issame< y > not match signature. but question is: why branch being evaluated @ all? sizeof...( args ) fal...

dos - Passing exclamation marks as parameters in batch subroutine call -

thanks community have learned how escape exlamation marks immediate use in batch delayedexpansion block. (use 2 escape carets not one, awesome) but can't seem find or figure out how pass contents of variable containing exclamation mark parameter batch subroutine. example: @echo off setlocal enabledelayedexpansion set variable=hello^^! echo "!variable!" call :subroutine "!variable:^^!=^^!!" pause exit :subroutine echo "%~1" exit/b output: "hello!" "hello" press key continue . . . i want second "hello" include exclamation mark. have tried various permutations of substring replacement on line 5 no avail. help you need different way variable replacing, , more carets. @echo off setlocal enabledelayedexpansion set variable=hello^^! echo "!variable!" call :subroutine %variable:!=^^^^^^^^^^!% exit /b :subroutine echo %~1 exit /b or quotes: call :subroutine "%variable:!=^^^!%...

python - Some advice on the style of different ways to limit line length to comply with PEP8 -

i updating code comply pep8 maximum line length. i have 2 questions on people think better style. first init of class (or function definition matter). people split arguments of function definition if line long this: def __init__(self, title, url, teaser, parsedate, updatedate, redis, id=none): or considered better split thát part second line otherwise long this: def __init__(self, title, url, teaser, parsedate, updatedate, redis, id=none): and secondly: in long if statements, don't find splitting of conditions add mucht clarity of code this: if self.redis.exists('article:%s' % self.url)\ , self.redis.hexists('article:%s' % self.url, 'id'): self.id = self.redis.hget('article:%s' % self.url, 'id') else: self.id = self.redis.incr('articleid') if written below, line definatily long,...

java - Sending JSON request to hipchat -

i making hipchat room work have send json request of: post /v1/rooms/message?format=json&auth_token=token http/1.1 host: api.hipchat.com content-type: application/x-www-form-urlencoded content-length: 138 room_id=10&from=alerts&message=a+new+user+signed+up so far have this: public static void send(string send){ url url = null; httpurlconnection conn = null; try{ url = new url("http://api.hipchat.com"); conn = (httpurlconnection)url.openconnection(); conn.setrequestmethod("post"); conn.setrequestproperty("content-type", "application/x-www-form-urlencoded"); conn.setrequestproperty("content-length", "138"); conn.setusecaches (false); conn.setdoinput(true); conn.setdooutput(true); dataoutputstream wr = new dataoutputstream( conn.getoutputstream ()); wr.writebytes (send); wr.flush (); wr.close (); input...