이것도 가능합니까? Windows 프로그램으로 다시 통신하는 데 사용해야하는 Mac에 Java 서버 프로그램이 있습니다. 나는 자바에서 작업 클라이언트를 가지고,하지만 난 그것을 VB.net에서 작동하도록하는 방법을 알아낼 수없는 것 ... 여기 VB.NET 클라이언트가있는 Java 소켓 서버?
자바 코드가
...import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
public class socketClient {
public static void main(String[] args) {
/**
* Define a host server
*/
String host = "10.1.1.194";
/**
* Define a port
*/
int port = 19999;
StringBuffer instr = new StringBuffer();
String TimeStamp;
System.out.println("SocketClient initialized");
try {
//Obtain an address object of the server
InetAddress address = InetAddress.getByName(host);
//Establish a socket connection
Socket connection = new Socket(address, port);
//Instantiate a BufferedOutputStream object
BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
/**
* Instantiate an OutputStreamWriter object with the optional
* character encoding.
*/
OutputStreamWriter osw = new OutputStreamWriter(bos, "US-ASCII");
TimeStamp = new java.util.Date().toString();
String process = "Initiate file transfer on " + host + " port " + port
+ " at " + TimeStamp + (char) 13;
//Write across the socket connection and flush the buffer
osw.write(process);
osw.flush();
/**
* Instantiate a BufferedInputStream object for reading /**
* Instantiate a BufferedInputStream object for reading incoming
* socket streams.
*/
BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
/**
* Instantiate an InputStreamReader with the optional character
* encoding.
*/
InputStreamReader isr = new InputStreamReader(bis, "US-ASCII");
//Read the socket's InputStream and append to a StringBuffer
int c;
while ((c = isr.read()) != 13) {
instr.append((char) c);
}
//Close the socket connection.
connection.close();
System.out.println(instr);
}
catch (IOException f)
{
System.out.println("IOException: " + f);
}
catch (Exception g)
{
System.out.println("Exception: " + g);
}
}
}
그리고 여기에 지금까지 가지고 내 VB.NET 코드 ...
Private clientSocket As Socket
Private host As String = "10.1.1.194"
Private port As Integer = 19999
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
Dim add As New IPEndPoint(IPAddress.Parse(host), port)
clientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
clientSocket.Connect(add)
Dim netStream As New NetworkStream(clientSocket, True)
Dim outstream As Byte() = System.Text.Encoding.ASCII.GetBytes("Initiate file transfer from " _
& System.Environment.MachineName & " on " & host & " port " & port & " at " & TimeOfDay)
netStream.Write(outstream, 0, outstream.Length)
netStream.Flush()
Catch ex As Exception
Debug.Write(ex.Message)
End Try
End Sub
은 ... 나는 VB에서 코드를 실행하는 경우, 그것은 응답, 이제이며이 때하는 것처럼 아무것도 (맥 내 콘솔에 표시되지 않습니다 나는 자바 클라이언트를 사용한다.) 그러나 VB 코드를 닫을 때, 나는 java.net.SocketException을 얻는다 : Connection reset error. 그의 외출.
소켓 프로그래밍에 관해서는 거의 아무것도 알지 못합니다. 누군가 나를 올바른 방향으로 밀어 넣을 수 있다면, 매우 감사하겠습니다!
와우, 나는 바보 야. 그걸 보지 못 했어. 완벽하게 작동합니다. 감사합니다! – Calvin