Quelques fix sur le code du serveur
This commit is contained in:
parent
623d5c307c
commit
c17ccbfb71
@ -1,6 +1,9 @@
|
||||
package com.bernard.murder;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.Stream.Builder;
|
||||
|
||||
public class BytesUtils {
|
||||
|
||||
@ -17,4 +20,17 @@ public class BytesUtils {
|
||||
buffer.put(data);
|
||||
}
|
||||
|
||||
public static Stream<Byte> toStream(ByteBuffer buffer){
|
||||
Builder<Byte> bldr = Stream.builder();
|
||||
|
||||
for(Byte b: buffer.array())
|
||||
bldr.add(b);
|
||||
|
||||
return bldr.build();
|
||||
}
|
||||
|
||||
public static void dump(ByteBuffer buffer) {
|
||||
System.out.println(toStream(buffer).limit(buffer.position()).map(b -> b.toString()).collect(Collectors.joining(",")));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -112,6 +112,7 @@ public class AudioServer {
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
System.out.println("Accepting request from "+senderAddress);
|
||||
break;
|
||||
case AudioServer.ASK_STREAMING:
|
||||
int listened = data.getInt();
|
||||
@ -163,10 +164,12 @@ public class AudioServer {
|
||||
ByteBuffer out2 = ByteBuffer.allocate(AudioServer.packetMaxSize);
|
||||
out2.put(AudioServer.GIVE_AUDIO_LIST);
|
||||
out2.putInt(mics.size());
|
||||
for(Entry<Integer, String> e : mics.entrySet()) {
|
||||
out2.putInt(e.getKey());
|
||||
BytesUtils.writeString(out2, e.getValue());
|
||||
for(Entry<Integer, String> mic : mics.entrySet()) {
|
||||
out2.putInt(mic.getKey());
|
||||
BytesUtils.writeString(out2, mic.getValue());
|
||||
}
|
||||
System.out.println("Sending audio list to "+senderAddress+" : ");
|
||||
BytesUtils.dump(out2);
|
||||
try {
|
||||
serveur.sendData(out2, senderAddress);
|
||||
} catch (IOException e1) {
|
||||
|
||||
@ -103,7 +103,7 @@ public class MicServer {
|
||||
|
||||
micId = deviceId;
|
||||
|
||||
serverAnswered.run();
|
||||
new Thread(serverAnswered).start();
|
||||
|
||||
if(micLine==null)
|
||||
try {
|
||||
|
||||
@ -112,6 +112,7 @@ public class Serveur {
|
||||
public void sendData(byte[] data, SocketAddress address) throws IOException {
|
||||
if(data.length < packetMaxLength) {
|
||||
DatagramPacket packet = new DatagramPacket(data, data.length,address);
|
||||
System.out.println("Sent "+packet.getLength()+" bytes to "+packet.getAddress());
|
||||
socket.send(packet);
|
||||
}else {
|
||||
short packetCount = (short) (data.length / (packetMaxLength-42));
|
||||
|
||||
@ -130,7 +130,7 @@ public class SpeakerServer {
|
||||
if(!isMicListUpToDate)askAudioList();
|
||||
while(!isMicListUpToDate) {
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
Thread.sleep(1);//XXX Can be interrupted here avec le bouton «Arreter»
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -162,7 +162,7 @@ public class SpeakerServer {
|
||||
return;
|
||||
|
||||
speakerId = deviceId;
|
||||
serverAnswered.run();
|
||||
new Thread(serverAnswered).start();
|
||||
if(speakerLine==null)
|
||||
try {
|
||||
initializeSpeakerDevice();
|
||||
@ -177,6 +177,7 @@ public class SpeakerServer {
|
||||
int thisMicId = data.getInt();
|
||||
mics.put(thisMicId,BytesUtils.readString(data));
|
||||
}
|
||||
System.out.println("Audio list given: "+mics);
|
||||
isMicListUpToDate=true;
|
||||
break;
|
||||
|
||||
|
||||
@ -69,14 +69,12 @@ public class GameManager {
|
||||
}
|
||||
|
||||
public void quickSave() {
|
||||
System.out.println("Quicksaving");
|
||||
File toSave = new File(quickSaveFilename());
|
||||
File tempOldSave = new File(quickSaveFilename()+".tmp");
|
||||
if(toSave.exists())toSave.renameTo(tempOldSave);
|
||||
|
||||
try {
|
||||
GameCreator.quickSave(toSave, partie,minelsQuicksaver.get());
|
||||
System.out.println("Quicksaved");
|
||||
if(tempOldSave.exists())tempOldSave.delete();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@ -73,6 +73,7 @@ public class EnceinteServeurFrame extends JFrame{
|
||||
NamedMicrophone[] micarray = new NamedMicrophone[list.size()];
|
||||
list.toArray(micarray);
|
||||
mics.setListData(micarray);
|
||||
System.out.println("Micros chargés: "+list);
|
||||
});
|
||||
serverControl.setText("Lancement");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user