我寫了一個服務器是用java這裏是代碼:ServerSocket java不讀取inputStream?
public mainClass()
{
try
{
ss = new ServerSocket(8080);
while (true)
{
socket = ss.accept();
System.out.println("It is accept!");
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//out = new PrintWriter(socket.getOutputStream(),true);
line = in.readLine();
System.out.println("you input is :" + line);
//out.close();
in.close();
socket.close();
}
}
catch (IOException e)
{
}
,我使用iPhone應用程序的客戶端。 現在我的問題是,服務器沒有讀取輸入流,而應用程序正在iphone上運行..但只要應用程序被終止,Java程序打印出已發送到服務器的字符串..不確定什麼是here..sorry發生的事情,如果這不是一個好問題..
- (void)viewDidLoad {
[super viewDidLoad];
socket = [[LXSocket alloc]init];
if ([socket connect:@"10.211.55.2" port:8080]) {
NSLog(@"socket has been created");
}
else {
NSLog(@"socket couldn't be created created");
}
@try {
[socket sendString:@"Hi This is a second test"];
}
@catch (NSException * e) {
NSLog(@"Unable to send data");
}
[super viewDidLoad];
}
感謝, TC
你能展示在iPhone上運行的相關代碼嗎(我認爲Objective C)? – MByD
添加了一些代碼... –