Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: Socket problem: read & write to same socket Date: Tue, 13 Mar 2012 22:03:43 +0000 (UTC) Organization: UK Free Software Network Lines: 47 Message-ID: References: <13556496.472.1331654504832.JavaMail.geo-discussion-forums@ynhs12> <4f5fc0a2$0$282$14726298@news.sunsite.dk> NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1331676223 30598 84.45.235.129 (13 Mar 2012 22:03:43 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Tue, 13 Mar 2012 22:03:43 +0000 (UTC) User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) Xref: csiph.com comp.lang.java.programmer:12989 On Tue, 13 Mar 2012 17:48:18 -0400, Arne Vajhøj wrote: > On 3/13/2012 5:33 PM, Martin Gregorie wrote: >> On Tue, 13 Mar 2012 09:01:44 -0700, liyaohua.bupt wrote: >> >>> I want to establish connection to a server(written by myself in Go >>> language), read from socket, and then write into socket. >>> >>> The connection can be established, and it reads correctly. But after >>> that and when I want to write to socket, it closes the connection. I >>> used wireshark to listen to the packets. I saw my program sent a FIN >>> to the server side. So the server receives nothing. >>> >>> Note that the server side only sends one line into socket. >>> >>> I later wrote a server in Java and a client in Go. They work fine in >>> both read and write. >>> >> Your code may accept one connection, read from and write to it, and >> close it, but its not a server because: >> >> (a) it doesn't listen for connections >> >> (b) it hasn't the right logical structure for accepting more than >> one connection either serially or in parallel with an existing >> connection >> >> (c) it stops itself without receiving a 'stop' command >> >> If your GO server uses similar logic, frankly I'm not surprised it >> isn't doing anything useful. > > I believe the code shown was for a client. > I don't think so for two reasons: Firstly, to quote the last line before the Java source "I later wrote a server in Java and a client in Go. They work fine in both read and write." Secondly, because it reads before it writes - something I've never seen a client do, though ymmv. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |