Reputation: 3911
I want to send a file using spring integration tcp module. So I made the server side using tcp-connection-factory.
<int-ip:tcp-connection-factory id="crLfServer"
type="server"
host="localhost"
port="7777"
single-use="true"
so-timeout="10000"
serializer="serializer"
deserializer="serializer"
/>
<bean id="serializer" class="com.sds.redca.core.normalizer.CustomSerializerDeserializer" />
<int-ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="crLfServer"
request-channel="toSA"
error-channel="errorChannel"/>
But, I made the client side with pojo class in java like the followings.
import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.Socket;
public class SendClient {
public static void main(String[] args) {
String serverIp = "localhost";
Socket socket = null;
try {
// 서버 연결
socket = new Socket(serverIp, 7777);
System.out.println("서버에 연결되었습니다.");
FileSender fs = new FileSender(socket);
fs.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class FileSender extends Thread {
Socket socket;
DataOutputStream dos;
FileInputStream fis;
BufferedInputStream bis;
public FileSender(Socket socket) {
this.socket = socket;
try {
dos = new DataOutputStream(socket.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void run() {
try {
String fName = "d:/test2/test.jpg";
dos.writeUTF(fName);
File f = new File(fName);
fis = new FileInputStream(f);
bis = new BufferedInputStream(fis);
int len;
int size = 4096;
byte[] data = new byte[size];
while ((len = bis.read(data)) != -1) {
dos.write(data, 0, len);
}
dos.flush();
dos.close();
bis.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Finally, I got error like the followings.
CRLF not found before max message length: 2048
I think I have to ignore serializer/deserializer for communication between two sides.
Upvotes: 1
Views: 1182
Reputation: 121177
Since you don't use Spring Integration IP on the client side you should take care about the end of message
manually.
From other side looks like your CustomSerializerDeserializer
is an extension of ByteArrayCrLfSerializer
, because the message CRLF not found before max message length:
is exactly from there.
So, the first: you should increase the maxMessageSize
for the CustomSerializerDeserializer
and second - you have to supply \r\n
bytes in the end of write
on the client. Or just use ByteArrayCrLfSerializer.serialize
there.
Upvotes: 1