3434import org .neo4j .driver .v1 .internal .spi .Logger ;
3535import org .neo4j .driver .v1 .internal .messaging .MessageFormat ;
3636
37+ import static java .nio .ByteOrder .*;
38+
3739public class SocketClient
3840{
41+ private static final int MAGIC_PREAMBLE = 0x6060B017 ;
42+ private static final int VERSION1 = 1 ;
43+ private static final int NO_VERSION = 0 ;
44+ private static final int [] SUPPORTED_VERSIONS = new int []{VERSION1 , NO_VERSION , NO_VERSION , NO_VERSION };
45+
3946 private final String host ;
4047 private final int port ;
4148 private final Logger logger ;
@@ -121,14 +128,15 @@ public void stop()
121128
122129 private SocketProtocol negotiateProtocol () throws IOException
123130 {
124- // TODO make this not so hard-coded
125- logger .debug ( "~~ [HANDSHAKE] [1, 0, 0, 0]." );
126- // Propose protocol versions
127- ByteBuffer buf = ByteBuffer .wrap ( new byte []{
128- 0 , 0 , 0 , 1 ,
129- 0 , 0 , 0 , 0 ,
130- 0 , 0 , 0 , 0 ,
131- 0 , 0 , 0 , 0 } );
131+ logger .debug ( "~~ [HANDSHAKE] [0x6060B017, 1, 0, 0, 0]." );
132+ //Propose protocol versions
133+ ByteBuffer buf = ByteBuffer .allocate ( 5 * 4 ).order ( BIG_ENDIAN );
134+ buf .putInt ( MAGIC_PREAMBLE );
135+ for ( int version : SUPPORTED_VERSIONS )
136+ {
137+ buf .putInt ( version );
138+ }
139+ buf .flip ();
132140
133141 channel .write ( buf );
134142
@@ -141,13 +149,12 @@ private SocketProtocol negotiateProtocol() throws IOException
141149 // Choose protocol, or fail
142150 buf .flip ();
143151 final int proposal = buf .getInt ();
144-
145152 switch ( proposal )
146153 {
147- case 1 :
154+ case VERSION1 :
148155 logger .debug ( "~~ [HANDSHAKE] 1" );
149156 return new SocketProtocolV1 ( channel );
150- case 0 : throw new ClientException ( "The server does not support any of the protocol versions supported by " +
157+ case NO_VERSION : throw new ClientException ( "The server does not support any of the protocol versions supported by " +
151158 "this driver. Ensure that you are using driver and server versions that " +
152159 "are compatible with one another." );
153160 default : throw new ClientException ( "Protocol error, server suggested unexpected protocol version: " +
0 commit comments