Home > Software engineering >  Vb winsocket sending pictures written in the Java client resources, receives the file cannot be disp
Vb winsocket sending pictures written in the Java client resources, receives the file cannot be disp

Time:10-11

Recently using vb to write a small simulation client used to send pictures of resources, using Java to write a small program used to receive store, but each time you receive the received resources are can't open, prompt the file has been damaged, I don't know what happened to the great god care solutions,
Here is the code;
Vb:
Option Explicit

Private Sub Form_Load ()
Winsock1 (0). The Protocol using TCP Protocol
=sckTCPProtocol 'Winsock1 (0). LocalPort=9999 'sets the local port
Winsock1 (0). The RemotePort=0 'Settings to connect remote port
Winsock1 (0). Set to Listen 'listening mode
End Sub

'accept connections
Private Sub Winsock1_ConnectionRequest (Index As an Integer, ByVal requestID As Long)
Dim PBag As New PropertyBag 'get image information
Dim PictureByt () As Byte 'save image

The Load Winsock1 (Winsock1. Count)

Winsock1 (Winsock1. Count - 1). The Accept requestID 'Accept new connections

'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
PBag. WriteProperty "Picture", Picture1. Picture
PictureByt=PBag. The Contents' access to containers Byte to PictureByt () in the array

'-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Winsock1 (Winsock1. Count - 1) SendData publishes the event PictureByt 'send data
End Sub

'==========================================================

Form the Client, it is necessary to control: Command1 Command2, Picture1, Winsock1, all is the default attribute

Option Explicit

Private Sub Command1_Click ()
Winsock1. Close 'Close connection
Winsock1. Protocol using TCP Protocol
=sckTCPProtocol 'Winsock1. LocalPort=0 'connection is established dynamically
Winsock1. RemotePort=9999 'Settings to connect remote port
Winsock1. Connect "192.168.1.124" 'Settings to Connect the computer name or IP address
'IP change to connect the IP

Command1. Enabled=False
End Sub

Private Sub Command2_Click ()
Dim bytData () As Byte 'receiving picture
Dim PBag As New PropertyBag 'image information

ReDim bytData (1 To Winsock1. BytesReceived) 'receive image size

Winsock1. GetData bytData 'read buffer data

PBag. Contents=bytData

Set Picture1. Picture=PBag. ReadProperty (" Picture ") 'Set the Picture

Command2. Enabled=False
End Sub

Private Sub Form_Load ()
Command1. Caption="connection"
Command2. Caption="display images"
End Sub

JAVA:

Package com. Yang. Pic_send;

Import the Java. IO. The File;
Import the Java. IO. FileInputStream;
Import the Java. IO. FileOutputStream;
Import the Java. IO. InputStream;
Import the Java. IO. OutputStream;
The import java.net.Socket;

Public class pic_sendDemo {

Public static void main (String [] args) throws the Exception {
The Socket soc=new Socket (" 10.150.89.203 ", 2000);
The File f=new File (" e: "+ File. The separator +" Yang "+ File. The separator +" pic_get. JPG ");
InputStream input=soc. GetInputStream ();
OutputStream out=new FileOutputStream (f);
Byte get []=new byte [4000000];
Int temp=0;
Int len=0;
System. Out.println (" is receiving... ");
/* while ((temp=input. The read ())!=1) {
System. The out. Print (" & gt;> & gt;" );
The get (len)=temp (byte);
Len++;
} */
Len=input. Read (get);
System. The out. Print (len);
Out. Write (a get, 0, len);

System. The out. Print (" from the ");
Input. The close ();
Soc. The close ();
System. The out. Print (" from the ");
//TODO automatically generated method stub

}

}
Don't know what is the agreement or something wrong please help me to solve 50 distribution

CodePudding user response:

I have done this,

CodePudding user response:

 'log each received byte 
I=0
LNX="- & gt; BYTE: "+ Right (" 0000000" + Hex (I), 8) + "-"
For I=0 To bytesTotal - 1
LNX=LNX + "" + Right (" 0" + Hex (iBuf (I)), 2)
If I Mod 16=15 Then
LogRX LNX
LNX="- & gt; BYTE: "+ Right (" 0000000" + Hex (I + 1), 8) + "-"
End the If
Next
I=bytesTotal - 1
If I Mod 16 & lt;> 15 Then
LogRX LNX
End the If
  • Related